SQL DatabaseLesson 56Free preview
SQL Foreign Key
This lesson is part of SQL · All levels
Summary
A foreign key is a column that refers to another primary key of a table to maintain a relationship between tables. This constraint rejects values that are not in its reference table so that the relational data remains intact. Foreign keys can also set the action when the reference line is deleted, e.g. CASCADE or SET NULL.
Key points
- Foreign key refers to a column of the type PRIMARY KEY or UNIQUE in another table.
- Refuses a value that is not in the reference table for reference integrity.
- On Delete and ON UPDATE can be set to: CASCADE, SET NULL, RESTRICT.
- The reference table must have an index on the reference column.
- The general many-to-one relationship is expressed by the foreign key.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.