SQL Constraints: SQL Create Table + Constraint Syntax
SQL Constraints: SQL Create Table + Constraint Syntax
SQL constraints are used to specify rules for the data in a table.
If there is any violation between the constraint and the data action, the
action is aborted by the constraint.
Constraints can be specified when the table is created (inside the CREATE
TABLE statement) or after the table is created (inside the ALTER TABLE
statement).
The NOT NULL constraint enforces a field to always contain a value. This
means that you cannot insert a new record, or update a record without
adding a value to this field.
UNIQUE Constraint
The UNIQUE constraint uniquely identifies each record in a database table.
The UNIQUE and PRIMARY KEY constraints both provide a guarantee for
uniqueness for a column or set of columns.
Note that you can have many UNIQUE constraints per table, but only one
PRIMARY KEY constraint per table.