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)
 How to find primary key of a Table

Author  Topic 

Peace2007
Posting Yak Master

239 Posts

Posted - 2008-08-25 : 01:41:51
Hi,

I need to find primary key(s)of a table through T-SQL statements.

Could you tell me which system functions I shall use?

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2008-08-25 : 01:47:32
sp_helpindex


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-08-25 : 02:25:51
[code]SELECT *
FROM INFORMATION_SCHEMA.TABLE_CONSTRAINTS c
INNER JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE cu
ON cu.CONSTRAINT_NAME=c.CONSTRAINT_NAME
WHERE c.TABLE_NAME='YourTableNameHere'
AND c.CONSTRAINT_TYPE='PRIMARY KEY'[/code]
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-08-25 : 02:43:00
or

EXEC sp_pkeys 'table name'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Peace2007
Posting Yak Master

239 Posts

Posted - 2008-08-25 : 02:45:43
Thanks all :)
Go to Top of Page
   

- Advertisement -