Cara mendapatkan HANYA TABEL referensi (yaitu tabel yang menggunakan tabel yang diberikan sebagai kunci asing dan tabel yang diberikan tabel menggunakan cara yang sama), Anda dapat menggunakan cuplikan kode ini:
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'))