SQL-ForeignKeyConstraint-Page6
πForeign Key Constraint
Foreign Key represent relationships between tables.
A foreign key is a column or group of columns whose values are derived from the primary key or unique key of some other table.
✅The table in which the foreign key is defined is called Foreign table or Detail table.
✅The table that defines the primary or unique key and is referenced by the foreign key is called the Primary table or Master table.
πFeatures
1)Master table cannot be updated if child records exists.
2)Records cannot be inserted or deleted into a detail table if corresponding records in the master table do not exist.
3)Records of the master table cannot be deleted if corresponding records in the detail table already exist.
πOn Delete Cascade
If this option is set, a delete operation in the master table will trigger a Delete operation for corresponding records in all detail tables.
If the On Delete Set Null option is set, a Delete operation in the Master table will set the value held by the foreign key of Detail tables to null. Refer Fig 1 as shown below.
πForeign Key at column level
πForeign Key at table level
πNaming Constraints
Comments
Post a Comment