How to find all the tables in SQL Server that share the same foreign key.
In [SQL Server], our Tables [Primary Key] are used in other tables. This is called a [Relational Database]. If, like me, you find you have too many tables to keep track of which Primary Key has been used in. Then, using [SQL Server Management Studio] ([SSMS]), we can run this script to find all tables that use the same foreign key.
Replace the 'MyTableID' with the ID you need to find the tables for.
[SQL Server - Find All Tables with same foreign key]
CFFCS | CarrzSynEdit: | SQL Script

SELECT TABLE_NAME, COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME = 'MyTableID'


To find all Table Names and their [Primary Key], use the article below to learn more.▼
Other Articles Related to this Entry.