find all foreign keys referencing a table in sql server

Solutions on MaxInterview for find all foreign keys referencing a table in sql server by the best coders in the world

showing results for - "find all foreign keys referencing a table in sql server"
Graeme
12 Apr 2018
1SELECT 
2   OBJECT_NAME(f.parent_object_id) TableName,
3   COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName
4FROM 
5   sys.foreign_keys AS f
6INNER JOIN 
7   sys.foreign_key_columns AS fc 
8      ON f.OBJECT_ID = fc.constraint_object_id
9INNER JOIN 
10   sys.tables t 
11      ON t.OBJECT_ID = fc.referenced_object_id
12WHERE 
13   OBJECT_NAME (f.referenced_object_id) = 'YourTableName'
Paula
14 Nov 2016
1--find all foreign keys referencing a table in sql server
2SELECT 
3   OBJECT_NAME(f.parent_object_id) TableName,
4   COL_NAME(fc.parent_object_id,fc.parent_column_id) ColName
5FROM 
6   sys.foreign_keys AS f
7INNER JOIN 
8   sys.foreign_key_columns AS fc 
9      ON f.OBJECT_ID = fc.constraint_object_id
10INNER JOIN 
11   sys.tables t 
12      ON t.OBJECT_ID = fc.referenced_object_id
13WHERE 
14   OBJECT_NAME (f.referenced_object_id) = 'YourTableName'
queries leading to this page
sql find foreign key references for tablefind all foreign keys referencing a tablefing all refernced table to foreing key sqllist of foreignkey references in sql databasesql get foregn key in querycheck all foreign keys sql serverfind all foreign keys referencing a table sql serverget foreign keylist of tables referencing another table sq 3bl serversql find foreign key referencessql where foreign key in listfind foreign key references sql serverget table by foreign keysql server get table foreign keyssql view all foreign keyfind all foreign keys in database sql serversql server fetch foreign key base and primary tablehow to get the foreign keys of a table in sqlsql server get foreign key mssql get foreign keys columnscheck where key is referenced in all tablesfind all tables with foreign key to tablefind foreign keys referencing table in sql serversql server find all foreign keys pointing to my tabllehow to get all foreign keys from sql serverhow to get foreign key in sql tablesql select all where foreign key is in the listsql list all foreign key constraints for columnsqlserver how to find out all foreign key referencessql server get table fksql find all foreign keys to a tablesql foreign key listsql server query all foreign keyssql show foreignkeyst sql get foreign keys of tableget foreign key references table sqlsql server finding foreign key referencesfind foreign keys referencing tableselect all foreign keys sql serverselect all foreign key constraints sql serverhow to get foreign key references in sql tablesql get foreign keyget foreign keys of table sqlget table of foreign key sqlhow to know foreign key references for a table in sql serverlist table foreign keys sqlsql server find all foreign key references to a tablehow to to get all foreign key column name and table name in sqlsql show table show foreign keymssql query show table primary and foreign keyssql server select 2a from sys foreign keys 3b for one tablesql find all foreign key referencessql find all tables with foreign key likeget all foreign keys of a table sql serverhow to find all foreign keys in sql serverget information from a table with a foreign keys sql servermssql find foreign key referencesfind out which table foreign key orcaleselect foreign key sqlsql see foreign keys of a columnsql list foreign key constraints for given columnsql show foreign keyssql find all tables with foreign keyfind the foreign key references in sql serversql server query all foreign tablesget all constraints dependent on certain table mssqlsql list all actions of foreign keyfind out which table foreign key sql serversql server get fk onlyfind all foreign keys referencing a table in sql serversql server get column foreign keysql server see what foreign keys reference columnsql get row and all foreign key referencessee all foreign keys sql serversql query foreign key like searchsql server get foreign keys definition referencing tablesql server find foreign key references by columnhow to get foreign key references in sqlhow to find the foreign key reference table in sql serverselect foreign key sql serversql server get foreign keys referencing tablet sql find foreign keys referencing tablefind all foreign keys referencing a table in sql server