Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Programatically determine the primary key

0 views
Skip to first unread message

Brett Hacker

unread,
Nov 26, 1998, 3:00:00 AM11/26/98
to
I have a need to determine the column name of the primary key for a table.
Is there a query or technique I can use to do this? I have looked at
sysindexes, syscolumns, sysconstraints, and several sp_help??? procedures. I
will need to get this column name within a sp I'm writing, and the table
name will be passed to the procedure.

Any help would be appreciated.

Brett Hacker, MCSE, MCT, CNE
Information Solutions Group, Inc.


K.R.Karthik

unread,
Nov 26, 1998, 3:00:00 AM11/26/98
to
Try using the sp_pkeys strored procedure in MS-Sql Server.
Store it in a resultset and go the resultset!COLUMN_NAME of each
until the end of the resultset to find all the pk's of the table.

Webb Deneys

unread,
Nov 30, 1998, 3:00:00 AM11/30/98
to
If it's an identity column, you can use the IDENTITYCOL pseudo-column.

If not, you'll have to use the sp_pkeys stored proc, either directly or by
reverse-engineering it to it's base tables and using them yourself.

- Webb

Brett Hacker <bre...@insolgroup.com> wrote in message
news:TQ672.1243$Cp3....@news13.ispnews.com...

0 new messages