Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Script: Getting PK and FK info Expand / Collapse
Author
Message
Posted Thursday, July 5, 2001 12:00 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Wednesday, October 2, 2013 9:26 AM
Points: 265, Visits: 185
Comments posted to this topic are about the content posted at http://www.sqlservercentral.com/columnists/rsharma/script:gettingpkandfkinfo.asp
Post #515
Posted Thursday, June 5, 2003 9:19 PM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Tuesday, June 21, 2011 10:03 AM
Points: 577, Visits: 102
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)
JOIN sysforeignkeys fk (nolock) on so.[id] = fk.fkeyid
join syscolumns sc (nolock) on fk.fkeyid = sc.id and fk.fkey = sc.colid
JOIN sysobjects so2 (nolock) on fk.rkeyid = so2.id
join syscolumns sc1 (nolock) on fk.rkeyid = sc1.id and fk.rkey = sc1.colid
JOIN sysobjects so1 (nolock) on fk.constid = so1.id
where so.name = X



Signature is NULL
Post #19800
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse