| Oracle FAQ | Your Portal to the Oracle Knowledge Grid | |
Home -> Community -> Usenet -> c.d.o.misc -> Re: primary key?
In article <5o002g$ook$1_at_news.nuri.net>,
swpark_at_namusoft.com (Sangwook Park) wrote:
>
> I'm using Oracle 7.3.
> I want to know the primary key of tables.
> How can I know that?
> I heard that the primary key was able to be found from tables by using ODBC.
> But, I'm using sql*plus and OCI.
> Let me know the primary key of tables .
> Thanks advance.
From JDBC, you can obtain the DatabaseMetaData and use the getPrimaryKey method. However, I have not been able to get this to work on Oracle. That is what I'm looking for now.
From Oracle, you can run the following SQL commands: SELECT CONSTRAINT_TYPE, CONSTRAINT_NAME FROM ALL_CONSTRAINTS WHERE TABLE_NAME=<your table>;
Constraint_types: P means primary key, U means unique, and C seems to mean NOT NULL. You want the CONSTRAINT_NAMEs where CONSTRAINT_TYPE=P SELECT COLUMN_NAME FROM ALL_CONS_COLUMNS WHERE TABLE_NAME=<your table> AND CONSTRAINT_NAME IN <pick the ones from previous select where type=P>
Hope its useful.
ehindle_at_sangacorp.com
> --
> Sangwook Park swpark_at_namusoft.com
> Namusoft http://www.namusoft.com
-------------------==== Posted via Deja News ====-----------------------
http://www.dejanews.com/ Search, Read, Post to Usenet
Received on Mon Jun 16 1997 - 00:00:00 CDT
![]() |
![]() |