如何找到表中的主键:
drop table test1 purge;
drop table test2 purge;
create table test1(ID number,NAME varchar2(20));
create table test2(ID number,NAME varchar2(20));
alter table test1 add constraint PK_T1_ID primary key (ID);--单一主键
alter table test2 add constraint PK_T2_ID_NAME primary key (ID,NAME);--联合主键
--查找主键SQL
select table_name, sumc(column_name) "主键列"
from (select b.table_name, column_name
from (select table_name, constraint_name
from user_constraints
where constraint_type = 'P') a,
user_cons_columns b
where a.constraint_name = b.constraint_name
and a.table_name = b.table_name
order by b.position)
group by table_name;
TABLE_NAME "主键列"
-------------------- --------------------
TEST1 ID
TEST2 ID,NAME
--sumc(column_name)如果不能用,则用wm_concat(column_name)