227k views
0 votes
What is a foreign key and how does it provide referential integrity?

1 Answer

3 votes

Answer:

By definition a foreign key of table A is a primary key of another table B, thereby establishing a link between them.

To provide referential integrity you can use these referential actions:

  • Cascade: If rows in table B are deleted, the matching foreign key columns in table A are deleted.
  • Set Null: If rows in table B are deleted, the matching foreign key columns in table A are set to null.
  • Set Default: If rows in table B are deleted, the matching foreign key columns in table A are set with the default value of the column.
  • Restrict: A value in table B cannot be deleted or updated while as it is referred to by a foreign key in table A.

User Marten Bauer
by
5.4k points