Re: Find the primary key column

From: Davide Gurgone <mortecerta_NOSPAM__at_libero.it>
Date: Sun, 19 Oct 2003 11:20:46 GMT
Message-ID: <isukb.311231$R32.10259055_at_news2.tin.it>


> Hi all,
> I need to find the primary key column of a specific table, using a query.
> What can I do that?

Find it!

select

 cons.constraint_name,
 cols.column_name,
 cols.position

from
 user_cons_columns cols,
 user_constraints cons
where
 cons.table_name = cols.table_name and
 cons.constraint_name = cols.constraint_name and
 cons.constraint_type = 'P' and
 cons.table_name = <table Name>

order by cols.position;

cons.constraint_type = 'P' extract only the Primary Key

Bye Received on Sun Oct 19 2003 - 13:20:46 CEST

Original text of this message