Constraints

Constraints enable the RDBMS enforce the integrity of the database automatically, without needing you to create triggers, rule or defaults.
Different types of constraints.
  • NOT NULL specifies that the column does not accept NULL values.
  • UNIQUE constraints enforce the uniqueness of the values in a set of columns.
  • PRIMARY KEY constraints identify the column or set of columns whose values uniquely identify a row in a table.
  • CHECK constraints enforce domain integrity by limiting the values that can be placed in a column.
  • FOREIGN KEY constraints identify the relationships between tables.
Column and Table Constraints
  • A column constraint is specified as part of a column definition and applies only to that column (the constraints in the earlier samples are column constraints).
  • A table constraint is declared independently from a column definition and can apply to more than one column in a table.

Table constraints must be used when more than one column must be included in a constraint.