How to find a table's primary key?


Is there an SQL or PL/SQL command to query the primary key of a table?

If not, where (in which tables) can I find information
about the primary keys of tables?



Ans1:
Here a litle script to search constraints:

select table_name, constraint_name, constraint_type,
       status, search_condition
   from all_constraints
   where owner=user
   order by table_name
/

constraint_type='P' = primary key

Johannes



Ans2:
select c.table_name TABLE_NAME, cc.column_name COLUMN_NAME,
substr('('||cc.position||')',1,8) POSITION
from dba_cons_columns cc, dba_constraints c
where c.constraint_name=cc.constraint_name
and c.constraint_type='P'


Ans3:
The information you want is in sys.dba_constraints (or all_constraints).  You
will also find related data in sys.dba_indexes and sys.dba_ind_columns.

Mark D. Powell



Ans4:
Try querying user_constraints where table_name = '<your_table_name>' and
constraint_type = 'P'.

HTH,
Roy



Ans5:
DBA_INDEXES, USER_INDEXES or ALL_INDEXES enable you to see table's indexes
which include primary key. DBA_IND_COLUMNS, USER_IND_COLUMNS or
ALL_IND_COLUMNS enable you to see which column is used as indexe.



Ans6:
A comfortable way to get this information is using a tool like Hora 3. See
http://www.keeptool.com for a free trial version of Hora 3.
 
 
Hosted by www.Geocities.ws

1