Foreign Keys | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

Foreign Keys

Hi There How can i find all the foreign on a table and the tables they reference? Thanks
Danny
And one more thing…..how different is it to find the relationship with other table in SQL 2005 than SQL Server 2000? Thanks
Danny
Script for 2000 SELECT fk_tc.TABLE_NAME,
fk_tc.CONSTRAINT_NAME,
pk_tc.TABLE_NAME,
pk_tc.CONSTRAINT_NAME
FROM Information_Schema.Table_Constraints as fk_tc
JOIN Information_Schema.Referential_Constraints as rc
on fk_tc.Constraint_Name = rc.Constraint_Name
JOIN Information_Schema.Table_Constraints as pk_tc
on rc.UNIQUE_CONSTRAINT_NAME = pk_tc.CONSTRAINT_NAME
order by
fk_tc.TABLE_NAME,
fk_tc.CONSTRAINT_NAME,
pk_tc.TABLE_NAME,
pk_tc.CONSTRAINT_NAME OR you can make use of the following two views…
select * from sys.foreign_keys
select * from sys.foreign_key_columns
Mohammed U.
Thanks alot!!!!!!!
Thats all i need. Best
Danny
Are you working in SQL 200 or 2005? In 2005 if you expand the table in object explorer it shows all the keys present on that table Satya
also you might try out sqlspec. see link in my sig below. www.elsasoft.org

]]>