03.13.08

Query to find orphan tables

Posted in Important SQL Query, Interview Questions, SQL Server, Utlities tagged , , , , at 12:44 pm by dayananthan

The following query will fetch the tables that doesn’t have relationships.

Select ST.[Name] as “Orphan Tables”

from Sys.Foreign_Keys as SFK Right Join Sys.Tables as ST

On ST.object_id = SFK.parent_object_id Or

ST.object_id = SFK.referenced_object_id

Where SFK.type is null