What is an Orphan and how do you find it ?

 Posted by Bharathi Cherukuri on 7/24/2012 | Category: Sql Server Interview questions | Views: 967 | Points: 40

The Foreign key value which exist in child table, without existing in primary key column in the parent table is known as an Orphan.

Example for finding an Orphan:

An orphan record exists when there is a Contact2 record but NOT a Contact1 record

SELECT * FROM Contact2 WHERE AccountNo NOT IN (SELECT AccountNo from Contact1)

Asked In: Many Interviews | Alert Moderator 

Comments or Responses

Login to post response