17,377
社区成员
发帖
与我相关
我的任务
分享
SQL>
SQL> create table test(c1 int, c2 int, c3 int);
Table created
SQL> alter table test add constraint PK_TEST primary key (c1);
Table altered
SQL> select table_name, column_name
2 from user_cons_columns where constraint_name = 'PK_TEST';
TABLE_NAME COLUMN_NAME
------------------------------ -----------------------------------------------
TEST C1
SQL> alter table test drop primary key ;
Table altered
SQL> alter table test add constraint PK_TEST primary key (c1,c2);
Table altered
SQL> select c1.colno , c1.cname, nvl2(c2.column_name,'true','false') PK
2 from col c1
3 left join user_cons_columns c2
4 on c1.tname = c2.table_name
5 and c1.cname = c2.column_name
6 and constraint_name = 'PK_TEST'
7 where c1.tname ='TEST' ;
COLNO CNAME PK
---------- ------------------------------ -----
1 C1 true
2 C2 true
3 C3 false
SQL> drop table test purge ;
Table dropped
SQL>
SQL>
SQL> create table test(c1 int, c2 int, c3 int);
Table created
SQL> alter table test add constraint PK_TEST primary key (c1);
Table altered
SQL> select table_name, column_name
2 from user_cons_columns where constraint_name = 'PK_TEST';
TABLE_NAME COLUMN_NAME
------------------------------ ---------------------------------------------------------
TEST C1
SQL> alter table test drop primary key ;
Table altered
SQL> alter table test add constraint PK_TEST primary key (c1,c2);
Table altered
SQL> select table_name, column_name
2 from user_cons_columns where constraint_name = 'PK_TEST';
TABLE_NAME COLUMN_NAME
------------------------------ ------------------------------------------------------
TEST C1
TEST C2
SQL> drop table test purge ;
Table dropped
SQL>