views:

39

answers:

3

Hi,

I wonder if there is a quicker way for this:

*"I have my Management Studio open and I have a Db table with manes of columns listed in front of me. I know FK_SomeTable field is a ForeignKey. But I do not know it is an FK on what table. And I need to learn that."*

So, normally I open the "Relationships" of that table, go one by one in the list which is framed by ab ugly narrow window and try to find it there, which is kind of boring and time loosing.

I do not want to query the system tables as well.

Isn't there a better and quicker way? There should be, isn't it?

Thanks

A: 

If you turn on database diagrams, you can create and alter the relationships of multiple tables simultaneously. Database diagrams show visual representations of each table selected, and you can define multiple diagrams. As far as I know thought there is not any method of retrieving relationship information without querying the system tables.

md5sum
A: 

Well I usually use the object explorer and go to the table I want and then look under Keys. You can widen the object explorer to see the fullname of the key. If it is named properly it probably has the table name of both the primary key and foreign key tables in it. If not you can script it to see. I had to search to find this relationships window you were talking about becasue I would never use the design window as we script all changes.

HLGEM
+1  A: 

How about this query? You could flip over to a query window and execute it quickly:

SELECT
    name,
    OBJECT_NAME(parent_object_id) 'Parent Table',
    OBJECT_NAME(referenced_object_id) 'Referenced Table'
FROM sys.foreign_keys

Gives you the FK name, and the two tables involved.

There's also a sys.foreign_key_columns system catalog view to give you the column information, if needed.

marc_s