Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 select primary key column

Author  Topic 

adityav22
Starting Member

1 Post

Posted - 2007-02-22 : 15:07:03
Is there a query that can return teh name of the primary key column of a table ?

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-02-22 : 15:23:36
SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS tc
INNER JOIN INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE ccu
ON tc.CONSTRAINT_NAME = ccu.CONSTRAINT_NAME
WHERE tc.TABLE_NAME = 'TableNameGoesHere' AND tc.CONSTRAINT_TYPE = 'PRIMARY KEY'


Tara Kizer
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-02-22 : 17:36:15
[code]exec sp_helpindex MyTableName[/code]

CODO ERGO SUM
Go to Top of Page
   

- Advertisement -