getting tables that link to a table

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • laredotornado

    getting tables that link to a table

    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
  • Bill E.

    #2
    Re: getting tables that link to a table

    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.rkey id 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

    Comment

    Working...