August 6, 2007 at 4:55 pm
Thanks in advance!
Does anyone have a Script to list all the Primary keys & Foreign Keys with table names in the database?
There are many tables in the db's & I need to find out which tables have what keys?
Regards.
August 6, 2007 at 5:21 pm
You want just the names of the PK's and FK's along with the related table name?
--Jeff Moden
Change is inevitable... Change for the better is not.
August 6, 2007 at 8:52 pm
Yes. I need the table names and associated PK & FK names.
Thanks!
August 7, 2007 at 4:58 am
This should do it...
SELECT TableID = sot.ID, TableName = sot.Name, IndexName = soi.Name, Type = soi.XType --PK or F FROM dbo.SysObjects sot --Table Info LEFT OUTER JOIN dbo.SysObjects soi --Index Info ON sot.ID = soi.Parent_Obj WHERE OBJECTPROPERTY(sot.ID,'IsMSShipped') = 0 --Is a user object, not an SQL Server object AND sot.XType = 'U' --Is a table AND soi.Xtype IN ('PK','F') ORDER BY TableName,Type DESC,IndexName
--Jeff Moden
Change is inevitable... Change for the better is not.
August 7, 2007 at 8:33 am
Jeff, Thanks! Yes it's listing all the names.
Regards.
August 7, 2007 at 6:26 pm
Cool. Thanks for the feedback
--Jeff Moden
Change is inevitable... Change for the better is not.
August 7, 2007 at 9:56 pm
It's rude to post the same question on multiple forums:
http://www.sqlservercentral.com/forums/shwmessage.aspx?forumid=5&messageid=388319#bm388701
August 8, 2007 at 2:50 am
Man, I gotta remember to check for those...
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply