Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

System table show if columns is part of PK?

Status
Not open for further replies.

kim1

Programmer
Nov 7, 2001
77
0
0
CA
Hi guys,

Is there any system table I can request to tell me if a columns is part of a primary key and Unique Key?

Table1
- ColA (PK)
- ColB (PK)
- ColC

ColA and ColB are Primary Keys

I have a loop that goes throught each column and I want to know if it is part of a primary key? or Unique Key? Is it possible?

Thanks for your help. Kim
 
I recommend using the INFORMATION_SCHEMA.TABLE_CONSTRAINTS view.

Use yourdatabase
go
Select *
From INFORMATION_SCHEMA.TABLE_CONSTRAINTS
Where (CONSTRAINT_TYPE='Unique'
Or CONSTRAINT_TYPE='Primary Key')

Also, see thread183-293476. Terry L. Broadbent - DBA
Computing Links:
faq183-874 contains "Suggestions for Getting Quick and Appropriate Answers" to your questions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top