Adding a Foreign Key While Creating a Table |
You can choose a foreign key as well as select foreign key options. Foreign key columns in the referencing table must map exactly to the primary key columns or unique index columns of the referenced table. The number of columns used in the foreign key and the schema of those columns must be the same in both the referencing and referenced tables.
A foreign key ensures referential integrity between two tables. How it performs this depends on the action chosen for the foreign key. When a record in the referenced column(s) is deleted or updated, the foreign key performs the action on the referencing column(s). The possible actions follow:
Set Null: Records in the foreign key column are set to Null if the user updates / deletes the corresponding records in the primary key or unique index column.
Cascade: The corresponding records in the referenced table are also updated or deleted.
Set Default: The foreign key record is set to a default value if the user updates / delete s corresponding records in the primary key or unique index column.
No Action: There is no action on the foreign key column if the user updates / deletes corresponding records in the primary key or unique index column.
The delete action of a foreign key may be different from the update action.
Related topic:
Creating
a Table
Adding a UNIQUE Constraint
Setting Advanced Table Options
Using Foreign Keys