Home » SQL & PL/SQL » SQL & PL/SQL » Sql query to get the primary key column of the table
Sql query to get the primary key column of the table [message #193511] Mon, 18 September 2006 00:45 Go to next message
manish5.k
Messages: 9
Registered: September 2006
Junior Member
Hi frnds


i need to get the key field of a table.
Pls help me, and provide me the query to get the key field.

thanks

manish
manish5.k@tcs.com

[Updated on: Mon, 18 September 2006 00:46]

Report message to a moderator

Re: Sql query to get the primary key column of the table [message #193519 is a reply to message #193511] Mon, 18 September 2006 01:51 Go to previous messageGo to next message
aorehek
Messages: 52
Registered: August 2006
Member
Try this ;


SELECT i.table_name, i.column_position, i.column_name, c.constraint_type  
FROM dba_ind_columns i, dba_constraints c WHERE c.table_name = :Table_Name 
AND c.constraint_type = 'P'
AND c.table_name = i.table_name
AND c.constraint_name = i.index_name

Re: Sql query to get the primary key column of the table [message #193521 is a reply to message #193511] Mon, 18 September 2006 01:58 Go to previous messageGo to next message
vghooli
Messages: 1
Registered: September 2006
Location: Bangalore
Junior Member
Hi Manish,

Plesae find below query, I think it will help you.

SELECT A.CONSTRAINT_NAME, A.TABLE_NAME, B.COLUMN_NAME FROM DBA_CONSTRAINTS A, DBA_CONS_COLUMNS B
WHERE A.owner = <SCHEMA_USER_NAME> AND B.owner = <SCHEMA_USER_NAME> AND A.CONSTRAINT_NAME = B.CONSTRAINT_NAME
AND A.constraint_type = 'P' ORDER BY A.CONSTRAINT_NAME

You need to enter Schema User Name.

Vasant
Re: Sql query to get the primary key column of the table [message #193550 is a reply to message #193521] Mon, 18 September 2006 03:54 Go to previous message
manish5.k
Messages: 9
Registered: September 2006
Junior Member
Thanks both of u.


it is working..

Previous Topic: DB Link between different oracle versions 9i to 10g
Next Topic: Update is very very slow, need help!
Goto Forum:
  


Current Time: Sun Dec 04 21:05:12 CST 2016

Total time taken to generate the page: 0.08327 seconds