Database Integrity: Foreign Key and Check Constraints for MySQL Database
The following constraints are commonly used in MySQL:
- Column Level
- NOT NULL - Ensures that a column cannot have a NULL value
- UNIQUE - Ensures that all values in a column are different
- DEFAULT - Sets a default value for a column if no value is specified
- PRIMARY KEY - A column or a set of columns that uniquely identifies each row in a table
- Table Level
CHECK - Ensures that the values under a column satisfies a specific condition
- Database Level
FOREIGN KEY - Ensures the values under a foreign key in a referencing match the values in the referenced table.
Foreign Key Constraints
Check Constraints