Skip to content

Instantly share code, notes, and snippets.

@jacobsimeon
Created August 28, 2012 16:18
Show Gist options
  • Save jacobsimeon/3499797 to your computer and use it in GitHub Desktop.
Save jacobsimeon/3499797 to your computer and use it in GitHub Desktop.
List tables with foreign key that references a given table
select t.name as TableWithForeignKey, fk.constraint_column_id as FK_PartNo , c.name as ForeignKeyColumn
from sys.foreign_key_columns as fk
inner join sys.tables as t on fk.parent_object_id = t.object_id
inner join sys.columns as c on fk.parent_object_id = c.object_id and fk.parent_column_id = c.column_id
where fk.referenced_object_id = (select object_id from sys.tables where name = 'PriorAuthorizationRequests')
order by TableWithForeignKey, FK_PartNo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment