Knowledge Walls
Gopal Rao
Mumbai, Maharashtra, India
Passcode:
Referencing a foreign key to the primary key of the same table
2325 Views
Referencing a foreign key to the primary key of the same table 
The point in doing this type of referencing is to create a hierarchy among the records and to maintain data consistency.

For eg:- Consider a table which has n number of columns, two among them are user_id and created_user_id.

user_id is the primary key and created_user_id is the foreign key which references the user_id.

By this way of referencing, we cannot delete a user_id record which appears as a created_user_id.

In simple terms if user_id is a child, and created_user_id is a father, You cannot kill a child without killing his father  (or kill a father to kill all of his children ;))
  Copyright © 2014 Knowledge walls, All rights reserved
KnowledgeWalls
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details