Show FK referenced table.column

  • Hi!

    Is there any way to query the parent table.column and the referenced table.column from a FK?

    I'v been lurking with system tables and views but can't find this type of info.

    Thanks so much!

  • Hi Miquel,

    Try this:

    select

    object_name(constid) as constraint_name
    ,object_name(fkeyid) as foreign_key_table,object_name(rkeyid) as referencing_table,col_name(fkeyid, fkey) as foreign_key_column,col_name(rkeyid, rkey) as referencing_column

    from

    sysforeignkeys

     

    You can then filter your results by foreign key by using a WHERE clause on constid (which is the id of the foreign key)

    Hope that helps,

  • Oh, thanks so much for the quick response.

    sysforeignkeys !!!

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply