getting tables that link to a table

getting tables that link to a table

am 02.04.2008 16:42:09 von laredotornado

Hi,

How can I run a query to figure out what tables and corresponding
columns link to any column in my table T?

Thanks, - Dave

Re: getting tables that link to a table

am 02.04.2008 21:50:16 von billmiami2

Try

SELECT obj.name AS ChildTable, col.name AS ChildColumn, obj2.name AS
ParentTable, col2.name AS ParentColumn
FROM sysforeignkeys fk
JOIN syscolumns col on col.id= fk.fkeyid and col.colid= fk.fkey
JOIN syscolumns col2 on col2.id=fk.rkeyid and col2.colid= fk.rkey
JOIN sysobjects obj on col.id=obj.id
JOIN sysobjects obj2 on col2.id=obj2.id

This will give you all of the foreign key relationships. Add a WHERE
clause to narrow it down to one table.

Bill E.
Hollywood, FL