Oracle中Constraint的状态参数initially与deferrable
在Oracle数据库中,关于约束的状态有下面两个参数:
initially (initially immediate 或 initially deferred)
deferrable(deferrable 或 not deferrable)
第1个参数,指定默认情况下,约束的验证时刻(在事务每条子句结束时,还是在整个事务结束时)。
第2个参数,指定了在事务中,是否可以改变上一条参数的设置。
如果不指定上述参数,默认设置是 initially immediate not deferrable。
注意:如果约束是not deferrable,那么它只能是initially immediate,而不能是initially deferred。
测试①,initially immediate:
SQL> create table nlist (
2 nid number
3 );
Table created
SQL> alter table nlist add constraint pk_nlist primary key (nid) initially immediate;
Table altered
SQL> insert into nlist values (1);
1 row inserted
SQL> insert into nlist values (1);
insert into nlist values (1)
ORA-00001: 违反唯一约束条件 (TEST.PK_NLIST)
测试②,initially deferred:
SQL> create table nlist (
2 nid number
3 );
Table created
SQL> alter table nlist add constraint pk_nlist primary key (nid) initially deferred;
Table altered
SQL> insert into nlist values (1);
1 row inserted
SQL> insert into nlist values (1);
1 row inserted
SQL> commit;
commit
ORA-02091: 事务处理已回退
ORA-00001: 违反唯一约束条件 (TEST.PK_NLIST)
测试③,initially immediate deferrable:
SQL> create table nlist (
2 nid number
3 );
Table created
SQL> alter table nlist add constraint pk_nlist primary key (nid) initially immediate deferrable;
Table altered
SQL> set constraint pk_nlist deferred;
Constraints set
SQL> insert into nlist values (1);
1 row inserted
SQL> insert into nlist values (1);
1 row inserted
SQL> commit;
commit
ORA-02091: 事务处理已回退
ORA-00001: 违反唯一约束条件 (TEST.PK_NLIST)
测试④,initially deferred deferrable:
SQL> create table nlist (
2 nid number
3 );
Table created
SQL> alter table nlist add constraint pk_nlist primary key (nid) initially deferred deferrable;
Table altered
SQL> set constraint pk_nlist immediate;
Constraints set
SQL> insert into nlist values (1);
1 row inserted
SQL> insert into nlist values (1);
insert into nlist values (1)
ORA-00001: 违反唯一约束条件 (TEST.PK_NLIST)
测试⑤:
SQL> create table nlist (
2 nid number
3 );
Table created
SQL> alter table nlist add constraint pk_nlist primary key (nid) initially deferred no deferrable;
alter table nlist add constraint pk_nlist primary key (nid) initially deferred no deferrable
ORA-01735: 无效的 ALTER TABLE 选项
转载自http://hi.baidu.com/linkzq/item/be23df424c9312e3bdf4511c
转载于:https://www.cnblogs.com/iImax/archive/2012/09/11/2680511.html
Oracle中Constraint的状态参数initially与deferrable相关推荐
- ORACLE中CONSTRAINT的四对属性
ORACLE中CONSTRAINT的四对属性 summary:在data migrate时,某些表的约束总是困扰着我们,让我们的migratet举步维艰,怎样利用约束本身的属性来处理这些问题呢?本文具 ...
- Oracle中含有recover 状态的数据文件环境中,做异机恢复
背景: 我们在一些恢复测试案例中,会经常遇到一些奇怪的问题,其中有的是源端数据文件不规范而导致恢复过程出错,比较常见的错误有: 数据文件名称重复(如:/oradata1/user01.dbf 和 /o ...
- oracle中constraint的使用,constraint用法总结 I .
Oracle中的约束简单介绍 约束 Including Constraints 在数据库中使用约束(constraints)是为了在该数据库中实施所谓的"业务规则"其实就是防止非法 ...
- oracle会话状态,oracle中会话的状态
我们可以通过oracle视图v$session来查看当前数据库中的所有会话信息,其中该视图有一列为status标志会话状态,oracle官方文档对这一列定义如下 STATUS VARCHAR2(8) ...
- oracle数据库offline,oracle中删除offline状态的数据文件
oracle在归档模式下: 我开始想单独删除一个表空间里的数据文件. 先查询想要删除的数据文件的相关信息:select * from v$datafile; alter database dat ...
- oracle中查找锁定状态的用户
SQL> desc dba_users; desc dba_users; 名前 NULL? 型 ----------------------------------------- ------- ...
- 默认约束 oracle,ORACLE约束(constraint):对象的强制规定
ORACLE约束(constraint):对象的强制规定 5种约束: NOT NULL 非空 NN UNIQUE 唯一 UK PRIMARY KEY 主键 PK FOREIGN ...
- Oracle中SQL解析的流程
Oracle中SQL解析的主要流程: 我们说的游标概念比较复杂,它可以是客户端程序中的游标,服务进程中的私有游标,以及服务器端共享池里的共享游标.假设一个游标被打开了,一般来说它的共享游标信息(包括执 ...
- 在Oracle中,如何定时清理INACTIVE状态的会话?
在Oracle中,如何定时清理INACTIVE状态的会话? 一般情况下,少量的INACTVIE会话对数据库并没有什么影响,但是,如果由于程序设计等某些原因导致数据库出现大量的会话长时间处于INACTI ...
最新文章
- 美多商城之支付(支付宝介绍)
- Split-plot设计 SAS实践
- 网络招聘“草莽时代”该结束了
- 数据库SQL优化大总结之 百万级数据库优化方案(转)
- vue.js初识(一)
- 29 MM配置-采购-采购申请-采购申请审批策略-编辑特性
- “iPhone 3 年内必死!”
- kafka consumer group 定义
- Mysql关键字 (MySQL 5.1参考手册)
- paip.提升安全性---登录密码出错次数检测
- Ubuntu 下搭建 GCC 交叉编译工具链
- Cisco 防火墙 SSH配置
- 计算机exce常用功能,EXCEL常用函数介绍(1)EXCEL 函数 -电脑资料
- 除了快,5G 有哪些关键技术?
- 无线局域网和搭建拓扑学习
- 怎么从SPSS的分析结果中得出回归方程?
- SqlServer的LDF文件丢失, 如何仅用MDF文件恢复数据库呢?(已解决)
- error: src refspec XXX matches more than one
- 【渝粤教育】电大中专计算机职业素养 (4)作业 题库
- 20190905-钴