Search code examples
sqlsql-serverforeign-keysprimary-keyforeign-key-relationship

Find all foreign keys constraints in database referencing a certain primary key


I want to find all foreign keys in my database that reference to a primary key of a certain table.

For example, I have a column A in table T which is the primary key. Now I want to find in which tables column A is referenced in a foreign key constraint?

One simple way I've considered is to check the database diagram, but this only works if a database is very small. It's not a very good solution for a database that has more than 50 tables.

Any alternatives?


Solution

  • Look at How to find foreign key dependencies in SQL Server?

    You can sort on PK_Table and PK_Column to get what you want