Oracle的Null Not Null 约束是可以通过alter table modify来修改的,但是check constraint却不可以。
比方说,将一个数值新加入到Check Constraint中,
SQL> create table dlb_test (id number not null primary key, xp char(1));
Table created.
SQL> alter table dlb_test add constraint dlb_const check (xp IN (’Y',’N'));
Table altered.
QL> alter table dlb_test modify constraint dlb_const check (xp In (’X',’Y',’N'));
alter table dlb_test modify constraint dlb_const check (xp In (’X',’Y',’N'))
*
ERROR at line 1:
ORA-00933: SQL command not properly ended
搜索OTN,根本找不Modify Check Constraint的语法。这种情况下只能重建。
SQL> alter table dlb_test add constraint dlb_const2 check (xp IN (’Y',’N',’X')) enable novalidate;
Table altered.
SQL> alter table dlb_test drop constraint dlb_const;
Table altered.
SQL> alter table dlb_test rename constraint dlb_const2 to dlb_const;
Table altered.
因为DDL Check Constaint 需要Row Cache Lock,并且要扫描列验证Check Constraint的数据完整性。当数据量很大或者要求在线修改,使用enable novalidate更为安全。