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)
 find if the column is a primary key

Author  Topic 

helixpoint
Constraint Violating Yak Guru

291 Posts

Posted - 2007-10-10 : 14:08:11
I am returning the columns with:
select column_name from information_schema.columns where table_name='tbl_Address'


Ones I have the columns, how can I check to see if it is a primary key?

Kristen
Test

22859 Posts

Posted - 2007-10-10 : 14:15:44
A number of ways, but IsPrimaryKey property of OBJECTPROPERTY() function will do it.

See OBJECTPROPERTY in Books Online

Kristen
Go to Top of Page

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-10-10 : 22:25:51
Or query information_schema.key_column_usage.
Go to Top of Page
   

- Advertisement -