Oracle Constraints

 Primary Key Constraint:

CREATE TABLE employees (
employee_id NUMBER PRIMARY KEY,
employee_name VARCHAR2(50));

Foreign Key Constraint:

CREATE TABLE orders (
order_id NUMBER PRIMARY KEY,
customer_id NUMBER,
FOREIGN KEY (customer_id) REFERENCES customers(customer_id));

Check Constraint:

CREATE TABLE employees (
employee_id NUMBER PRIMARY KEY,
employee_name VARCHAR2(50),
salary NUMBER,
CONSTRAINT age CHECK (age > 18));

Not Null Constraint:

CREATE TABLE customers (
customer_id NUMBER PRIMARY KEY,
customer_name VARCHAR2(50) NOT NULL);

Composite Constraints:

CREATE TABLE sales (
order_id NUMBER,
product_id NUMBER,
quantity NUMBER,
PRIMARY KEY (order_id, product_id),
FOREIGN KEY (order_id) REFERENCES orders(order_id),
FOREIGN KEY (product_id) REFERENCES products(product_id));

Unique Constraint:

CREATE TABLE students (
student_id NUMBER UNIQUE,
student_name VARCHAR2(50));

Constraints Views:

select constraint_name, constraint_type,table_name from user_constraints;

Popular posts from this blog

Oracle Database 19C Performance Tunning - PART 1

Oracle RMAN Backup And Restore

Oracle Patching Using Opatch Utility

Welcome to DBA Master – Database Tips, Tricks, and Tutorials

Oracle 19c Database Software Installation in OEL8

PostgreSQL Triggers

PostgreSQL Opensource Installation in RHEL or Oracle Linux(OEL) 8 and above

PostgreSQL Cursor

PostgreSQL Procedures

PostgreSQL User & Role Management