Important Points About SQL FOREIGN KEY Constraint
- A FOREIGN KEY is a field (or collection of fields) in one table, that refers to the PRIMARY KEY in another table.
- The table containing the foreign key is called the child table, and the table containing the candidate key is called the referenced or parent table.
- A table can have multiple FOREIGN KEY constraints.
- When defining a FOREIGN KEY constraint, you can specify what happens when a referenced row in the parent table is deleted or updated. This is done using the ON DELETE and ON UPDATE clauses followed by the CASCADE, SET NULL, or NO ACTION option.
- The FOREIGN KEY constraint in SQL is used to maintain the referential integrity of data within the database.
SQL Foreign Key Constraint
SQL Foreign Key constraint establishes a relationship between two tables by requiring values in one table’s column to match values in another table’s primary key column.