8. SQL Statements : ALTER TABLE : Constraint Specifications
 
Share this page                  
Constraint Specifications
When a constraint (see Constraints) is added to a table, the table is checked to ensure that its contents do not violate the constraint. If the contents of the table do violate the constraint, the DBMS Server returns an error and does not add the constraint.
The following table summarizes the elements of the constraint_clause:
Type
Keyword
Example
Referential
REFERENCES
ALTER TABLE dept
ADD CONSTRAINT chkmgr
FOREIGN KEY(mgr) REFERENCES emp(ename) ON DELETE SET NULL;
Unique
UNIQUE
ALTER TABLE emp
ADD UNIQUE (eno, ename);
Check
CHECK
ALTER TABLE emp
ADD CHECK (salary>0);
Primary key
PRIMARY KEY
ALTER TABLE emp
ADD CONSTRAINT ekey
PRIMARY KEY(eno);