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

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Find PK column

Re: Find PK column

From: rachel carmichael <wisernet100_at_gmail.com>
Date: Wed, 8 Jun 2005 09:04:31 -0400
Message-ID: <2e7118730506080604aae61e6@mail.gmail.com>


Your query doesn't select for primary key, or constraint columns.

select cl.table_name, cl.column_name, cl.constraint_name from user_cons_columns cl, user_constraints c where cl.table_name=3Dc.table_name
and cl.constraint_name=3Dc.constraint_name and c.constraint_type=3D'P'
and cl.table_name=3D'MATERIAL'
order by cl.table_name,cl.position
/

Oh, and unless you created the table using mixed case (double-quoting around the table name in the create statement), Oracle will store it in upper case.

On 6/8/05, Kean Jacinta <jacintakean_at_yahoo.com> wrote:
> Hi ,
>=20
> I am trying to get the table primary key and the
> column name. How can i query that.
>=20
> THis is the result i want :
>=20
> table_name columns_name constraint_name
> ---------- ------------- ---------------
> Material bookid bookid_pk
>=20
>=20
> currently i have tried
>=20
> select u.table_name, u.column_name, c.constraint_name
> from user_tab_columns u, user_constraints c
> where u.table_name=3Dc.user_constraints
> and u.table_name=3D'Material'
>=20
> I can't get the result correctly
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
>=20
> __________________________________
> Discover Yahoo!
> Find restaurants, movies, travel and more fun for the weekend. Check it o=
ut!
> http://discover.yahoo.com/weekend.html
>=20
> --
> http://www.freelists.org/webpage/oracle-l
>

--
http://www.freelists.org/webpage/oracle-l
Received on Wed Jun 08 2005 - 09:09:33 CDT

Original text of this message

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