Re: How to find primary key?
From: Stephan Born <stephan.born_at_beusen.de>
Date: Wed, 22 Mar 2000 10:45:37 +0100
Message-ID: <38D89641.F15FC6DC_at_beusen.de>
from
user_cons_columns cols,
user_constraints cons
where
order by cols.position
Date: Wed, 22 Mar 2000 10:45:37 +0100
Message-ID: <38D89641.F15FC6DC_at_beusen.de>
> determine the primary key of the current table
>
>
Try this
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 = <current table>
order by cols.position
cons.constraint_type = 'P' only selects for <P>rimary keys
> My primary concern, now, is Oracle although I'm hoping to impliment this
> in as portable a fashion as possible.
I do not know whether the views user_cons_columns and user_constraints exist
in the same form
on other dbms
Regards, Stephan
-- --------------------------------------------------------------- Dipl.-Inf. (FH) Stephan Born | beusen Consulting GmbH fon: +49 30 549932-0 | Landsberger Allee 392 fax: +49 30 549932-21 | 12681 Berlin mailto:stephan.born_at_beusen.de | Germany --------------------------------------------------------------- PGP-Key verfügbar | PGP-Key available ---------------------------------------------------------------Received on Wed Mar 22 2000 - 10:45:37 CET