Constraints are the rules enforced on the data columns of a table. These 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 database.
If any interruption occurs between the constraint and data action, the action is failed. Some of the most commonly used constraints are NOT NULL, PRIMARY KEY, FOREIGN KEY, AUTO_INCREMENT, UNIQUE KEY, etc.
syntax to create a constraint for a table:
SQL categories the constraints into two levels:
Column Level Constraints: These constraints are only applied to a single column and limit the type of data that can be stored in that column.
Table Level Constraints: These constraints are applied to the entire table and limit the type of data that can be entered.