Script: Getting PK and FK info

  • Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rsharma/script:gettingpkandfkinfo.asp

  • This query provides "To" and "From" Fields as well. I like your query for PK constraints...

    select

    so1.Name as FKConstraint,

    so.Name as FromTable,

    sc.Name as FromColumn, so2.Name as ToTable, sc1.Name as ToColumn

    From sysobjects so (nolock)

    JOINsysforeignkeys fk (nolock) on so.[id] = fk.fkeyid

    joinsyscolumns sc (nolock) on fk.fkeyid = sc.id and fk.fkey = sc.colid

    JOINsysobjects so2 (nolock) on fk.rkeyid = so2.id

    joinsyscolumns sc1 (nolock) on fk.rkeyid = sc1.id and fk.rkey = sc1.colid

    JOINsysobjects so1 (nolock) on fk.constid = so1.id

    whereso.name = X

    Signature is NULL

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

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