Foreign key columns

  • Guys,

    Below is the query that I use to generate foreign key name, child table and parent table, but I would also like to add parent and child columns which are part of the relationship to the select list.

    select o.name, a.name as child, b.name as parent

    from sysobjects o inner join sysforeignkeys f

    on f.constid = o.id inner join sysobjects a on a.id = f.fkeyid

    inner join sysobjects b on b.id = f.rkeyid

    Is there anyway to do this

    Any comments and suggestions would help

    Thanks

  • select o.name, a.name as child, b.name as parent, cc.name as childcol, pc.name as parentcol

    from sysobjects o inner join sysforeignkeys f

    on f.constid = o.id

    inner join sysobjects a on a.id = f.fkeyid

    inner join sysobjects b on b.id = f.rkeyid

    inner join syscolumns cc on cc.colid = f.fkey and cc.id = f.fkeyid

    inner join syscolumns pc on pc.colid = f.rkey and pc.id = f.rkeyid

    Greg

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

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