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

       Fig 1

👉Naming Constraints


When constraints are defined, database engine assigns a unique name to each constraint.
The convention used by Oracle is Sys_Cn where n is a numeric value that makes the constraint name unique.
Constraints can also be given a unique user-defined name along with the constraint definition.
A constraint can then be dropped by referring to the constraint by its name.

Comments

Popular posts from this blog

Javascript-OOPs(Part4)-Polymorphism- (10)

Javascript-OOPs(Part3)-Inheritance - (9)

Javascript-OOPs(Part1)-Objects - (7)