Constraints in MYSQL


☞ They are some set of rules created to apply data validations.

☞ They ensure accuracy, correctness and reliability of data.

☞ It is not mandatory to define constraints for each attribute of a table.

☞ SQL provides the following constraints :

1. PRIMARY KEY
2. NOT NULL
3. UNIQUE
4. DEFAULT
5. FOREIGN KEY

PRIMARY KEY

☞ The field which uniquely identifies each record in a table.


NOT NULL

☞ It ensures that the column cannot have NULL values.

☞ NULL means missing/unknown/not applicable values.


UNIQUE

☞ It ensures that all the values in a column are distinct/unique.


DEFAULT

☞ It allows to assign a default value if the value is not provided or given.


FOREIGN KEY

☞ The column which refers to value of an attribute defined as the primary key in another table.