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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Query to identify primary key column in a table

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2007-02-27 : 16:03:56
Vijay Kasarabada writes "Is there a query that can identify the primary key column in a table. I mean teh query on a table should return a column name that is the primary key for that table."

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2007-02-27 : 23:46:05
here are a few ways:

select * from INFORMATION_SCHEMA.TABLE_CONSTRAINTS where constraint_type='PRIMARY KEY'

select * from sys.key_constraints

exec sp_helpconstraint 'Person.Address'


www.elsasoft.org
Go to Top of Page
   

- Advertisement -