By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,379 Members | 1,439 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,379 IT Pros & Developers. It's quick & easy.

getting tables that link to a table

P: n/a
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
Apr 2 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Apr 2 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.