Referential integrity Rules:
- Referenced
tables are called Parent tables.
- Referencing
tables are called Child tables.
- Parent tables contain
referenced Primary keys.
- Child tables contain
referencing Foreign keys.
- A row cannot exist in a table as foreign key value without a corresponding primary key value . Which basically means the a child should have a parent.
Golden Rule : A child should have a Parent
- When
inserting record to child table, FK column is validated against the PK
column and if the value does not exist on the parent table, it returns an
error.
- When updating record on child
table, FK column value is validated against the PK columns and if the new
value does not exist on the parent table, it returns an error.
- When deleting a record from child table, no validations are done.
- When
inserting a new record to the Parent table, NO validations are done.
- While Deleting row from Parent
table, validations are made to see if there are FK dependencies. If there is any child row dependent on this
parent row then it returns an error.
- When updating the PK value , validations are made to see if there are FK dependencies. If there is any child row dependent on old value of the PK then it returns an error.
No comments:
Post a Comment