A foreign key is a primary key or candidate key in the referenced table, it could consists of one or many columns. The foreign key is added to the referencing table. When the foreign keys between the tables are established, the referential integrity relationship
in database system is hence maintained.
While establishing foreign key in the referencing table, we may impose constraints on the foreign key, the constraint will affect how the referencing table's row behaved when it was updated or deleted in the referenced table or vice versa.
There are several constraints, i.e. CASCADE, RESTRICT, SET DEFAULT, SET NULL, NO ACTION.
Here is the example,
CASCADE - Whenever rows in the master (referenced) table are deleted, the respective rows of the child (referencing) table with a matching foreign key column will get deleted as well. A foreign key with a cascade delete means that if a record in the parent table is deleted, then the corresponding records in the child table will automatically be deleted. This is called a cascade delete.
RESTRICT - A row in the referenced table cannot be updated or deleted if dependent rows still exist. In that case, no data change is even attempted. Should not be allowed.
Copyright © 2026 eLLeNow.com All Rights Reserved.