Class-6 (Constraint-Unique, Not Null, Check, Foreign Key)
Class-6 (Constraint-Unique, Not Null, Check, Foreign Key)
)
----------------------------
(2) Unique
----------
> It will not allow duplicate value in that column
> It allows NULL value to store in the column
> We can have any number of unique key in a table
COMMIT;
COMMIT;
(4) CHECK
---------
> It is used to check a condition
> If the condition is true then it allows to perform INSERT/UPDATE operation
COMMIT;
> It is used to create a relationship between a parent table and child table
> To create a link/relationship , we must have a common column in both the table
> The table on which we will create a Foreign Key is called as Child table
> The child table can depend with a parent table
> This is called as Parent-Child /Primary-Foreign Key relationship.
Syntax
-------
CONSTRAINT <Constraint Name> FOREIGN KEY (<Child Column Name>) REFERENCES <Parent
Table Name>(<Parent column name>)
Scenario
--------
Employee---->Working----->Under----->Department
Who is child?Employee
Who is parent?Department
Table Name:Department
---------------------
Column Name Data Type Size Constraint
----------- --------- ---- ----------
DEPTNO NUMBER 2 PRIMARY KEY
DNAME VARCHAR2 20 NOT NULL
LOC VARCHAR2 20 NOT NULL
Table Name:Employee
---------------------
Column Name Data Type Size Constraint
----------- --------- ---- ----------
EMPNO NUMBER 4 PRIMARY KEY
ENAME VARCHAR2 30 NOT NULL
SAL NUMBER 8 NOT NULL
DEPTNO NUMBER 2 FOREIGN KEY