Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Get the primary key name of a table
On Thu, 17 Mar 2005 07:44:14 GMT, "Robert Wehofer"
<thalion77_at_graffiti.net> wrote:
>
>Hello!
>
>Thank you for your advices.
>
>I now use following statement to get the primary key of a table:
>
>SELECT COL.COLUMN_NAME FROM USER_CONS_COLUMNS COL, USER_CONSTRAINTS CON
>WHERE COL.TABLE_NAME = 'TABLENAME' AND COL.TABLE_NAME = CON.TABLE_NAME
>AND COL.CONSTRAINT_NAME = CON.CONSTRAINT_NAME AND CON.CONSTRAINT_TYPE='P';
>
>I hope this statement works in all oracle versions.
>
>Robert
>
Apart from the fact it should be con.table_name = '<table name>' and col.table_name = con.table_name is redundant, this statement will work from Oracle 6.0 onwards
-- Sybrand Bakker, Senior Oracle DBAReceived on Thu Mar 17 2005 - 02:04:23 CST
![]() |
![]() |