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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

primary key column

Status
Not open for further replies.

hilbrink

Programmer
Dec 8, 2000
38
NL
Does anybody know if it is possible to find the name of the column over which a primary key is defined?

With the use of systemtables i can find the names of tables which have a primary key:

SELECT sysobjects.name
FROM sysobjects, sysconstraints
WHERE sysobjects.xtype = 'U'
AND sysconstraints.constid in
(SELECT id
FROM sysobjects
WHERE xtype = 'PK')

But i would like to know the name of the column of each table over which the primary key is defined.
The column sysconstraints.colid only contains zero's...

Thanks in advance.


 
sp_helpconstraint will show (among other things) the PK for a given table, but not all tables in one shot. Robert Bradley
teaser.jpg

 
thank you, Robert.

But i would rather like to know how to get the result with the use of system tables. Because i need to know the primary key column of all tables (i think using one query in stead of using sp_helpconstraint several times will save some time).

Does anybody have any idea how to do it?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top