ORACLE10G中列属性NULLABLE与CHECK约束及主键约束的关系2

Create TABLE ZWXTEST04
(
   ID integer    not null     ,
   NAME varchar  (100)  not null primary key    
) cache;

 

select * from user_constraints where table_name='ZWXTEST04';

SELECT * FROM USER_TAB_COLUMNS where table_name='ZWXTEST04';

产生三个约束。CCP。两个列的NULLABLE均为N。

 

ALter table ZWXTEST04 drop constraint SYS_c0039012;

 

删除NAME列自动产生的约束。

select * from user_constraints where table_name='ZWXTEST04';

SELECT * FROM USER_TAB_COLUMNS where table_name='ZWXTEST04';

 

观察到NAME列的NULLABLE仍然为N。

 

ALter table ZWXTEST04 drop constraint SYS_c0039013;

删除主键约束

 

select * from user_constraints where table_name='ZWXTEST04';

SELECT * FROM USER_TAB_COLUMNS where table_name='ZWXTEST04';

 

至此NAME列的NULLABLE自动恢复为Y。

 

结论:

       当列为主键列时,无法使用MODIFY设置其列为NULL,当显示声明的NOT NULL 被去除时,需要手工去清除自动产生的CHECK。

 

目标:

 

Create TABLE ZWXTEST04
(
   ID integer    not null     ,
   NAME varchar  (100)  primary key    
) cache;

 

差异语句:

    寻找NAME上的自动约束,删除它。

      

 

 

 

 

 

 

posted @ 2010-11-11 20:16  秦秋随  阅读(2499)  评论(0编辑  收藏  举报