Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Find Parent of a Table

Author  Topic 

Behseini
Starting Member

1 Post

Posted - 2011-04-07 : 15:50:26
Hi Guys
Could you please let me know what SQL query I can run to get the parent of a specified table?
I find this code which is providing a list of child tables

SELECT object_name(parent_object_id)As 'Childs List'
FROM sys.foreign_keys
WHERE object_name(referenced_object_id) ='Stores'

How can I run a code like this to list parent of "Stores" table?
Thanks

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2011-04-07 : 20:04:07
I think what you are asking for is how to find the referenced objects given a name of a table where there is a foreign key. If so, it is similar to what you already did as in
SELECT object_name(referenced_object_id)As 'Parent List'
FROM sys.foreign_keys
WHERE object_name(parent_object_id) ='Stores'
Go to Top of Page

ahmeds08
Aged Yak Warrior

737 Posts

Posted - 2011-04-11 : 08:44:26
you can see the help for the STORES table ...you can see the table references there...
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-04-16 : 18:27:19
You could also make use of this....

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=143772

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page
   

- Advertisement -