Modify check constraint

April 14th, 2007 | Categories: Boring | Tags:

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更为安全。

Del.icio.us Google书签 Digg Live Bookmark Technorati Furl Yahoo书签 Facebook 百度搜藏 新浪 ViVi 365Key 网摘 天极网摘 和讯网摘 博拉网 POCO 网摘 饭否 QQ 书签 Digbuzz 我挖网 Mister Wong
No comments yet.