Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

WHERES MY PRIMARY KEY?????

Status
Not open for further replies.

howzatUK

IS-IT--Management
Oct 14, 2005
23
0
0
GB
How can i find the name of a primary key in oracle? where can i find the name of the primary key and what fields of a tbale make up that primary key?

Thanks

a desperate novice
 
Use the user_constraints table. constraint_type set to 'P' indicates a primary key constraint

Code:
select *
from user_constraints
where constraint_type = 'P'
and table_name = <table_name>
 
Correction, use the user_con_constriants table for the colunms. This statement ought to help.

Code:
select B.COLUMN_NAME, B.TABLE_NAME
from USER_CONS_COLUMNS B, user_constraints A 
where A.conStraint_type = 'P'
and A.table_name = <table_name>
and b.constraint_name = a.CONSTRAINT_NAME
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top