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.

Similar Reads

Foreign Key in SQL

A foreign key is a column or a combination of columns in a table that establishes a link between two tables in a relational database. It refers to the primary key in another table, creating a relationship between them....

Syntax

There are two ways to add a foreign key to the table in SQL – CREATE TABLE and ALTER TABLE statement...

SQL Foreign Key Constraint Example

Let’s look at some examples of the FOREIGN KEY Constraint in SQL....

SQL DROP FOREIGN KEY

To remove a Foreign key from a table, use the ALTER TABLE command. The syntax to drop a primary key is:...

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....