Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Get the primary key name of a table

Re: Get the primary key name of a table

From: Sybrand Bakker <postbus_at_sybrandb.demon.nl>
Date: Thu, 17 Mar 2005 09:04:23 +0100
Message-ID: <mdei31hkcr1favppq2pg7qvgslbhup6qdr@4ax.com>


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 DBA
Received on Thu Mar 17 2005 - 02:04:23 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US