ITPub博客

首页 > 数字化转型 > ERP > constraint deferrable immediate check

constraint deferrable immediate check

原创 ERP 作者:itpremier 时间:2010-12-07 10:54:05 0 删除 编辑

-- define a deferrable constraint allow check constraint when a transaction is commited, by default with immediate constraint allow check constraint after DML operation .

-- allow primary key check deferrable.

alter table t1 add constraint pk_t1 primary key (id) initially deferred ;

insert into t1 (id) values (1) ;

insert into t1 (id) values (1) ;

commit ; -- report error here.

-- allow foreign key check deferrable.

alter table t2 add constraint fk_t2_t1 foreign key (dept_id) referencing t1

initially deferred ;

insert into t2 (id,dept_id) values (1,999) ;

commit ; -- report error here.

-- switch constraint check at which points.

alter session set constraint=deferrable ;

set constraints all deferrable /immediate;

set constraint pk_t1 deferrable /immediate;

[@more@]

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/350519/viewspace-1042712/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: house
请登录后发表评论 登录
全部评论

注册时间:2008-11-27

  • 博文量
    253
  • 访问量
    773712