Constraints are used to limit the type of data that can go into a table. This ensures the
accuracy and reliability of the data in the table. If there is any violation between the
constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to a column,
and table level constraints apply to the whole table
Constraints can be specified when the table is created with the CREATE TABLE statement, or
after the table is created with the ALTER TABLE statement.
Followings are some most common MySQL constraints :
➢ NOT NULL : Ensures that a column cannot have a NULL value
➢ UNIQUE :Ensures that all values in a column are different
➢ PRIMARY KEY :Primary Constraint of a relational table, uniquely identifies each record in the table. In
some tables, combination of more than on attributes is declared as primary key.
➢ FOREIGN KEY :Foreign Constraint is a non-key attribute whose value is derived from the primary key of
another table. The relationship between two tables is established with the help of foreign key.
➢ CHECK :Ensures that the values in a column satisfies a specific condition
SDAD
10