k_murli_krishna
asked on
Table and PK columns
1) We have Oracle 10g r2 on windows 2000 server.
2) How to find primary keys fields of a set of tables in a database using a Query?
Query output should be
Tablename, primarykey field name
2) How to find primary keys fields of a set of tables in a database using a Query?
Query output should be
Tablename, primarykey field name
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
i agree with peterside7, only a comment:
you need to include the owner in the resultset if retrieving from dba_tables because you will get scrambled data if several users use the same table names in their schema.
what do you think?
you need to include the owner in the resultset if retrieving from dba_tables because you will get scrambled data if several users use the same table names in their schema.
what do you think?
Yes, exactly, you need the owner :
select ucc.owner, 'table= '||ucc.table_name||' col'||ucc.position||' = '||ucc.column_name
from dba_constraints uc
inner join dba_cons_columns ucc on
uc.constraint_name = ucc.constraint_name
where uc.constraint_type = 'P'
and uc.owner not in ('SYS','SYSTEM')
order by ucc.table_name,ucc.positio n
select ucc.owner, 'table= '||ucc.table_name||' col'||ucc.position||' = '||ucc.column_name
from dba_constraints uc
inner join dba_cons_columns ucc on
uc.constraint_name = ucc.constraint_name
where uc.constraint_type = 'P'
and uc.owner not in ('SYS','SYSTEM')
order by ucc.table_name,ucc.positio
select 'table= '||ucc.table_name||' col'||ucc.position||' = '||ucc.column_name
from dba_constraints uc
inner join dba_cons_columns ucc on
uc.constraint_name = ucc.constraint_name
where uc.constraint_type = 'P'
and uc.owner not in ('SYS','SYSTEM')
order by ucc.table_name,ucc.positio