केवल तालिका प्राप्त करने का तरीका संदर्भ (अर्थात तालिका जो दी गई तालिका को विदेशी कुंजी के रूप में उपयोग करती है और तालिका जो तालिका उसी तरह उपयोग करती है) आप इस कोड स्निपेट का उपयोग कर सकते हैं:
declare @tableName varchar(64);
set @tableName = 'TABLE';
select
SO_P.name as [parent table]
,SC_P.name as [parent column]
,'is a foreign key of' as [direction]
,SO_R.name as [referenced table]
,SC_R.name as [referenced column]
,*
from sys.foreign_key_columns FKC
inner join sys.objects SO_P on SO_P.object_id = FKC.parent_object_id
inner join sys.columns SC_P on (SC_P.object_id = FKC.parent_object_id) AND (SC_P.column_id = FKC.parent_column_id)
inner join sys.objects SO_R on SO_R.object_id = FKC.referenced_object_id
inner join sys.columns SC_R on (SC_R.object_id = FKC.referenced_object_id) AND (SC_R.column_id = FKC.referenced_column_id)
where
((SO_P.name = @tableName) AND (SO_P.type = 'U'))
OR
((SO_R.name = @tableName) AND (SO_R.type = 'U'))