SQL-Contraints
SQL-Contraints
1
Constraints
A property that can be set on a column or set of columns
table or later.
The constraints can be applied at the following levels:
Constraints cont..
The constraints can be applied at the following levels:
Column Level Constraint: A constraint is called
UNIQUE
PRIMARY KEY
FOREGIN KEY
CHECK Constraint
NULL/NOT NULL
It determine whether a column can be blank or not.
or empty string.
NULL means that no entry has been made. It can only be
key.
It restricts duplication of rows and dose not allow NULL
values.
A primary key that consist of two or more columns is
column level.
Example 1(Column - Level)
The following example creates a primary key at column
level.
CREATE TABLE DEPT
(DEPTNO NUMBER(5) PRIMARY KEY,
DNAME VARCHAR2(14) CONSTRAINT enum_ukey
UNIQUE,
LOC VARCHAR2(13));
Example 2 (Table - Level)
The following example creates a primary key at table level.
key.
Foreign key is used to create a link between the data in
two table.
The link created between two tables is based upon
common filed.
This filed is a PRIMARY key in the parent table and
table.
REFERENCES: identifies the table and column in parent table.
JOB VARCHAR2(15),
HIREDATE DATE,
MGR NUMBER(4),
SAL NUMBER(7,2),
COMM NUMBER(7,2),
EMP table.