Summary - Data integrity
- SQL course
- Intermediate
- Lesson 99/115
- 5 min
Build a consistent table with PRIMARY KEY, FOREIGN KEY and CHECK.
Summary - Data integrity
Entity, referential and domain integrity together ensure data consistency. Triggers add custom checks.
-- PRIMARY KEY (entity)
-- FOREIGN KEY (referential)
-- CHECK + NOT NULL (domain)Summary integrity types.
Practice Summary - Data integrity
Summary: add a FOREIGN KEY to orders.
Starter code
-- summary integrity
ALTER TABLE ordersSample solution
ALTER TABLE orders
ADD FOREIGN KEY (customer_id) REFERENCES customers(id)Expected output
Tablo güncellendi
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Which integrity does a foreign key provide?
- Entity
- Referential Correct answer
- Domain
- Trigger
Explanation: A foreign key provides referential integrity.
2 Summary - Data integrity: match the terms
| Term | Meaning |
|---|---|
PRIMARY KEY |
entity |
FOREIGN KEY |
referential |
CHECK |
domain |
TRIGGER |
custom |