ORA-02447: cannot defer a constraint that is not deferrable

一个constraint如果被定义成deferrable那么这个constraints可以在deferred和imediate两种状态相互转换。

deferred只在transaction中有效,也就是只可以在transaction过程中使constraint失效,但如果transaction commit的话,transaction会变成immediate。

1* create table cons_parent (id number(10),name varchar2(10))

SQL> /

Table created.

SQL> create table cons_child (id number(10),name varchar2(10));

Table created.

1* alter table cons_parent add primary key (id)

SQL> /

Table altered.

alter table cons_child add constraints chi_fk_par foreign key (id)

references cons_parent(id)

SQL> alter table cons_child add constraints chi_fk_par foreign key (id)

2 references cons_parent(id)

3 /

Table altered.

一个constraints默认是NOT DEFERRABLE的。

1 select constraint_name||‘ ‘||deferrable from all_constraints

2* where constraint_name=‘CHI_FK_PAR‘

SQL> /

CONSTRAINT_NAME||‘‘||DEFERRABLE

---------------------------------------------

CHI_FK_PAR NOT DEFERRABLE

NOT DEFERRABLE的不能在deferred和imediate两种状态相互转换

SQL> set constraints chi_fk_par deferred;

SET constraints chi_fk_par deferred

*

ERROR at line 1:

--解决办法:删除该约束后,并重建deferrable约束。

SQL> alter table cons_child drop constraints chi_fk_par;

Table altered.

1 alter table cons_child add constraints chi_fk_par foreign key (id)

2* references cons_parent(id) deferrable

SQL> /

Table altered.

1 select constraint_name||‘ ‘||deferrable from all_constraints

2* where constraint_name=‘CHI_FK_PAR‘

SQL> /

CONSTRAINT_NAME||‘‘||DEFERRABLE

---------------------------------------------

CHI_FK_PAR DEFERRABLE

一个constraint如果被定义成deferrable那么这个constraints可以在deferred和imediate两种状态相互转换

SQL> set constraints chi_fk_par immediate;

Constraint set.

1* insert into cons_child values (2,‘llll‘)

SQL> /

insert into cons_child values (2,‘llll‘)

*

ERROR at line 1:

ORA-02291: integrity constraint (SYSTEM.CHI_FK_PAR) violated - parent key not found

SQL> set constraints chi_fk_par deferred;

Constraint set.

SQL> insert into cons_child values (2,‘llll‘);

1 row created.

SQL> commit;

commit

*

ERROR at line 1:

ORA-02091: transaction rolled back

ORA-02291: integrity constraint (SYSTEM.CHI_FK_PAR) violated - parent key not found

deferrable会影响CBO的计划,并且正常情况下没有应用的必要,所以建议不要修改,而用系统默认的non deferrable

本篇文章摘自:关于表约束constraint \\constraints 三个注意的地方

ORA-02447: cannot defer a constraint that is not deferrable

时间: 2024-11-13 08:08:25

ORA-02447: cannot defer a constraint that is not deferrable的相关文章

ORA_ERROR大全

转自:http://blog.csdn.net/haiross/article/details/12839229 常见错误:-60 ORA00060: deadlock detected while waiting for resource 一般错误:  - 1 ORA00001: unique constraint (.) violated  -17 ORA00017: session requested to set trace event  -18 ORA00018: maximum nu

Oracle日常维护脚本

1.正常停库流程     ps -ef|grep LOCAL=NO|cut -c 9-15|xargs kill -9      shutdown immediate; 2.备份数据库     backup database format '/home/orarch_ccmpdb1/backup2/full_%d_%s_%p_%u.%T';      backup current controlfile format '/home/orarch_ccmpdb1/backup2/controlfi

为何在查询中索引未被使用 (Doc ID 1549181.1)

* 为何在查询中索引未被使用 (Doc ID 1549181.1) To Bottom 文档内容 用途   排错步骤   快速检查   表上是否存在索引?   索引是否应该被使用?   索引本身的问题   索引列或者索引的前置列是否在单表(non-join)查询的 Where 条件中(predicate list)?   索引列是否用在连接谓词中(join predicates)?   索引列在 IN 或者多个 OR 语句中?   索引列是否被函数修改?   隐式类型转换(implicit ty

Oracle DBA需掌握的命令集锦(推荐)

第一章:日志管理 1.forcing log switches sql> alter system switch logfile; 2.forcing checkpoints sql> alter system checkpoint; 3.adding online redo log groups sql> alter database add logfile [group 4] sql> ('/disk3/log4a.rdo','/disk4/log4b.rdo') size 1

Oracle 数据库命令个人总结

一.日志管理 1.强制日志切换(forcing log switches) alter system switch logfile; 2.强制执行检查点(forcing checkpoints) alter system checkpoint; 3.增加一个重做日志组 (adding online redo log groups) alter fatabases add logfile [ group 4 ] ('/disk3/log4a.rdo','/disk4/log4b.rdo') siz

【Oracle】常用语句集合

1 oracle常用经典SQL查询 2 常用SQL查询: 3 4 1.查看表空间的名称及大小 5 6 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size 7 from dba_tablespaces t, dba_data_files d 8 where t.tablespace_name = d.tablespace_name 9 group by t.tablespace_name; 10 11 2.查看表空间物

oracle常用经典SQL查询

1 常用SQL查询: 2 3 1.查看表空间的名称及大小 4 5 select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size 6 from dba_tablespaces t, dba_data_files d 7 where t.tablespace_name = d.tablespace_name 8 group by t.tablespace_name; 9 10 2.查看表空间物理文件的名称及大小 11 12 sel

Oracle学习基本知识点总结

 以下是我总结的OCP教程的知识点,以备参考之用! 1, What's Oracle Server? ·         It's a database management system that provides an open, comprehensive, integrated approach to information management. ·         Consists of an Oracle instance and an Oracle database 2,What

OCP学习基本知识点总结

 下面是我总结的OCP教程的知识点.以备參考之用. 1, What's Oracle Server? ·         It's a database management system that provides an open, comprehensive, integrated approach to information management. ·         Consists of an Oracle instance and an Oracle database 2,What