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

To get Table and column name for Primary Keys. Expand / Collapse
Author
Message
Posted Wednesday, September 26, 2007 9:34 PM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, October 9, 2014 2:21 PM
Points: 148, Visits: 91
Comments posted to this topic are about the item To get Table and column name for Primary Keys.

Thanks
Mohit Nayyar
http://mohitnayyar.blogspot.com/
"If I am destined to fail, then I do have a purpose in my life, To fail my destiny"
Post #403311
Posted Saturday, November 13, 2010 7:59 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Saturday, November 13, 2010 7:59 PM
Points: 1, Visits: 1
Sorry for the three year old reply,

You are right, it is a bit complicated. Your method may not return the columns in the correct order. Might I suggest:

USE Case_Management
SELECT o.name, c.name
FROM sysindexes ix
JOIN sysobjects o ON ix.id = o.id
JOIN sysobjects pk ON ix.name = pk.name
AND pk.parent_obj = ix.id
AND pk.xtype = 'PK'
JOIN sysindexkeys ixk on ix.id = ixk.id
AND ix.indid = ixk.indid
JOIN syscolumns c ON ixk.id = c.id
AND ixk.colid = c.colid
WHERE o.name = 'MAIL_MESSAGES'
ORDER BY ixk.keyno

Art
Post #1020397
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse