Hello All,
Many time, We want to know that, What are all the tables who have referenced a column as a "foreign key" which is a "Primary Key" of other table.
Example:-- In a database I have one Company table which stores company information with CompanyId as a primary key. We wants to list all the tables which are using "CompanyId" as a foreign key.
Solution:----
SELECT * FROM sys.foreign_keys WHERE type='F' AND OBJECT_NAME(referenced_object_id)='Company'
EXEC sp_fkeys 'Company'
Above SQL statement will provide you the desired output.
0 Comment(s)