Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Server - view all foreign key dependencies

Tags:

sql

sql-server

I want to find all of the db objects which are dependent on a given table, including other tables which reference the given table through foreign keys. I tried using "sp_depends" and it gives me the sprocs, views, and triggers but doesn't tell me what other tables have foreign keys to the given table. Any help?

like image 460
thenoob Avatar asked Mar 09 '11 16:03

thenoob


1 Answers

select OBJECT_NAME(parent_object_id), OBJECT_NAME(referenced_object_id)
    from sys.foreign_keys
    where referenced_object_id = object_id('SchemaName.TableName')
like image 76
Joe Stefanelli Avatar answered Sep 28 '22 16:09

Joe Stefanelli