MySQL DatabaseLesson 52Free preview
MySQL Constraints
This lesson is part of MySQL · All levels
Summary
Constraints are built-in rules of the database that restrict the type of value that can be entered into a column or table. MySQL recognizes several major constraints: primary key, foreign key, unique, not, check, and default. With constraint, data validation is done directly by the database so that data remains consistent even when input from multiple applications.
Key points
- Constraint maintains data integrity by rejecting rules-breaking values
- Main types: primary key, foreign key, unique, not, check, default
- Constraints can be written directly at the time of creating tables or added to the ALTER tables.
- If the data violates the constraint, the INSERT/UPDATE operation will be rejected by error.
- The constraint naming makes it easier to manage and remove later
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.