Modify check constraint

 

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

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值