SQL DatabaseLesson 52Free preview
SQL Constraints
This lesson is part of SQL · All levels
Summary
Constraints are rules applied to columns or tables to maintain the quality and integrity of data. Its main types include NOT, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, and DEFAULT. With constraint, the database rejects data that violates the rules from the beginning.
Key points
- Constraints prevent invalid data from entering the database.
- The main types are: NOT, UNIQUE, PRIMARY KEY, FOREIGN KEY, CHECK, DEfault.
- It can be written inline at the time of the CREATE TABLE or added via the ALTER TABLE.
- The primary key combines the NOT and UNIQUE terms on the identity column.
- Foreign Key keeps the relationship between tables consistent.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.