Difference between revisions of "SQL Constraints"
From Lianjapedia
Yvonne.milne (Talk | contribs) |
Yvonne.milne (Talk | contribs) |
||
| Line 11: | Line 11: | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
| − | + | |[[CHECK Table Constraint|CHECK]] | |
|- | |- | ||
| − | |[[ | + | |[[ERROR Table Constraint|ERROR]] |
|- | |- | ||
| − | |[[ | + | |[[FOREIGN KEY Table Constraint|FOREIGN KEY]] |
|- | |- | ||
| − | |[[ | + | |[[INDEX Table Constraint|INDEX]] |
|- | |- | ||
| − | |[[ | + | |[[KEY Table Constraint|KEY]] |
|- | |- | ||
| − | |[[ | + | |[[ONAFTERDELETE Table Constraint|ONAFTERDELETE]] |
| + | |- | ||
| + | |[[ONAFTERINSERT Table Constraint|ONAFTERINSERT]] | ||
| + | |- | ||
| + | |[[ONAFTERUPDATE Table Constraint|ONAFTERUPDATE]] | ||
| + | |- | ||
| + | |[[ONCLOSE Table Constraint|ONCLOSE]] | ||
| + | |- | ||
| + | |[[ONBEFOREDELETE Table Constraint|ONBEFOREDELETE]] / [[ONDELETE Table Constraint|ONDELETE]] | ||
| + | |- | ||
| + | |[[ONBEFOREINSERT Table Constraint|ONBEFOREINSERT]] / [[ONINSERT Table Constraint|ONINSERT]] | ||
| + | |- | ||
| + | |[[ONOPEN Table Constraint|ONOPEN]] | ||
| + | |- | ||
| + | |[[ONROLLBACK Table Constraint|ONROLLBACK]] | ||
| + | |- | ||
| + | |[[ONBEFOREUPDATE Table Constraint|ONBEFOREUPDATE]] / [[ONUPDATE Table Constraint|ONUPDATE]] | ||
| + | |- | ||
| + | |[[PRIMARY KEY Table Constraint|PRIMARY KEY]] | ||
| + | |- | ||
| + | |[[UNIQUE Table Constraint|UNIQUE]] | ||
|- | |- | ||
|} | |} | ||
| Line 28: | Line 48: | ||
{| class="wikitable" width="100%" | {| class="wikitable" width="100%" | ||
| − | + | |[[AUTO_INCREMENT Column Constraint|AUTO_INCREMENT]] | |
| + | |- | ||
| + | |[[AUTOINC Column Constraint|AUTOINC]] | ||
| + | |- | ||
| + | |[[CALCULATED Column Constraint|CALCULATED]] | ||
| + | |- | ||
| + | |[[CHECK Column Constraint|CHECK]] | ||
| + | |- | ||
| + | |[[CHOICES Column Constraint|CHOICES]] | ||
| + | |- | ||
| + | |[[DEFAULT Column Constraint|DEFAULT]] | ||
| + | |- | ||
| + | |[[DESCRIPTION Column Constraint|DESCRIPTION]] | ||
| + | |- | ||
| + | |[[ERROR Column Constraint|ERROR]] | ||
| + | |- | ||
| + | |[[FOREIGN KEY Column Constraint|FOREIGN KEY]] | ||
| + | |- | ||
| + | |[[HELP Column Constraint|HELP]] | ||
| + | |- | ||
| + | |[[NOCPTRANS Column Constraint|NOCPTRANS]] | ||
| + | |- | ||
| + | |[[NOT NULL Column Constraint|NOT NULL]] | ||
| + | |- | ||
| + | |[[NULL Column Constraint|NULL]] | ||
| + | |- | ||
| + | |[[PICTURE Column Constraint|PICTURE]] | ||
|- | |- | ||
| − | |[[ | + | |[[PRIMARY KEY Column Constraint|PRIMARY KEY]] |
|- | |- | ||
| − | |[[ | + | |[[RANGE Column Constraint|RANGE]] |
|- | |- | ||
| − | |[[ | + | |[[RECALCULATE Column Constraint|RECALCULATE]] |
|- | |- | ||
| − | |[[ | + | |[[REFERENCES Column Constraint|REFERENCES]] |
|- | |- | ||
| − | + | |[[SET CHECK Column Constraint|SET CHECK]] | |
|- | |- | ||
| − | |[[UNIQUE Column Constraint|UNIQUE]] | + | |[[UNIQUE Column Constraint|UNIQUE]] |
|- | |- | ||
|} | |} | ||
Revision as of 05:27, 6 March 2015
Purpose
To define rules that help to provide data integrity
See Also
ALTER TABLE, CREATE TABLE, GRANT, REVOKE
Description
A constraint is used to define rules that help to provide data integrity. There are two different types of constraints, TABLE constraints, which do not require any column information and column constraints, which are specific to the column name specified. You must have ALTER privilege on the table. The table will be locked for EXCLUSIVE use during the operation.
Table Constraints
| CHECK |
| ERROR |
| FOREIGN KEY |
| INDEX |
| KEY |
| ONAFTERDELETE |
| ONAFTERINSERT |
| ONAFTERUPDATE |
| ONCLOSE |
| ONBEFOREDELETE / ONDELETE |
| ONBEFOREINSERT / ONINSERT |
| ONOPEN |
| ONROLLBACK |
| ONBEFOREUPDATE / ONUPDATE |
| PRIMARY KEY |
| UNIQUE |
Column Constraints
| AUTO_INCREMENT |
| AUTOINC |
| CALCULATED |
| CHECK |
| CHOICES |
| DEFAULT |
| DESCRIPTION |
| ERROR |
| FOREIGN KEY |
| HELP |
| NOCPTRANS |
| NOT NULL |
| NULL |
| PICTURE |
| PRIMARY KEY |
| RANGE |
| RECALCULATE |
| REFERENCES |
| SET CHECK |
| UNIQUE |