Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


To get Table and column name for Primary Keys.


To get Table and column name for Primary Keys.

Author
Message
Mohit Nayyar
Mohit Nayyar
SSC-Enthusiastic
SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)SSC-Enthusiastic (148 reputation)

Group: General Forum Members
Points: 148 Visits: 94
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"
artvanhecke
artvanhecke
Forum Newbie
Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)Forum Newbie (1 reputation)

Group: General Forum Members
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
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search