Posted by: aank76 | October 4, 2007

Show the Primary Key of A Table in Oracle

When making a query that needs joining two or more tables, you need to know the primary key/s of the tables.
The command DESCRIBE <TABLE_NAME> will not show you the primary key.
To get the primary key, use this query:

SELECT B.COLUMN_NAME FROM ALL_CONSTRAINTS A, ALL_CONS_COLUMNS B
WHERE A.CONSTRAINT_NAME=B.CONSTAINT_NAME AND A.OWNER=B.OWNER AND
A.TABLE_NAME=<TABLE_NAME> AND A.CONSTRAINT_TYPE='P';

Change <TABLE_NAME> with the table name.

Advertisement

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Categories

Follow

Get every new post delivered to your Inbox.