【问题标题】:column not null deferrable列不为空可延迟
【发布时间】:2011-01-14 18:39:26
【问题描述】:

在 Oracle 中,延迟约束仅在提交时检查。

在 NOT NULL 约束的情况下,DEFERRABLE 子句是什么意思? 例如

create table test(a number not null deferrable, b number);
insert into test(a,b) values (222, 111);
commit;

在这些陈述之后,我认为下面的代码会起作用

update test set a = null where b = 111;
delete test where b = 111;
commit;

但事实并非如此。

两种定义有什么区别?

create table test1(a number not null deferrable, b number);
create table test2(a number not null, b number);

【问题讨论】:

    标签: oracle data-integrity


    【解决方案1】:

    这里有两个选项。您需要使用下面显示的命令设置要在事务中延迟的约束

    SET CONSTRAINTS ALL DEFERRED;
    

    这应该在执行您定义的UPDATE 语句之前运行。

    或者,您可以在表定义中将约束设置为INITIALLY DEFERRED

    create table test(a number not null initially deferred deferrable, b number);
    

    完成上述任一操作后,您应该能够运行问题中的 DML。

    【讨论】:

    • 是的,你是对的。使用 INITIALLY DEFERRED 我的代码有效。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多