Wednesday 13 March 2013

DDL - Part 8 - Referential Integrity



Referential integrity Rules:

  1. Referenced tables are called Parent tables.
     
  1. Referencing tables are called Child tables.
     
  2. Parent tables contain referenced Primary keys.
     
  3. Child tables contain referencing Foreign keys.
     
  4. 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

  1. 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.
     
  2. 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.
     
  1. When deleting a record from child table, no validations are done.

  1. When inserting a new record to the Parent table, NO validations are done.
     
  2. 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.
     
  1. 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