Initially immediate
This is the default when neither initially immediate nor initially deferred has been specified.
The constraint is checked after each SQL statement.
create table init_immediate (
id number primary key initially immediate,
data varchar2(50)
);
Initially deferred
The constraint is checked when a transaction ends.
drop table init_immediate;
create table init_immediate (
id number primary key initially deferred,
data varchar2(50) not null initially deferred
);
insert into init_immediate values ( null, 'one');
insert into init_immediate values ( 3, null);
insert into init_immediate values ( 8, 'eight');
insert into init_immediate values ( 3, 'two');
update init_immediate set id = 1 where data = 'one';
update init_immediate set id = 2 where data = 'two';
update init_immediate set data = 'three' where id = 3;
commit;
It will be OK.
ORA-02447
A not deferrable constraint cannot be set to initially deferred,
it raises an
ORA-02447: cannot defer a constraint that is not deferrable which seems logical:
create table no_no_ora_02447 (
id number primary key not deferrable initially deferred,
data varchar2(50)
);
Deferrable constraint
create table cons_deferrable_pk_tab (
a number,
b varchar2(10),
c number not null deferrable,
d date,
primary key (a, b) deferrable
);
create table cons_deferrable_fk_tab (
z,
y,
x varchar2(10),
foreign key (z,y) references cons_deferrable_pk_tab deferrable
);
Now we insert data to the table will fails, because reference table has not been inserted data yet.
insert into cons_deferrable_fk_tab values (1, 'one', 'foo');
ORA-02291: 整合性制約(ZOLO.SYS_C005382)に違反しました - 親キーがありません
set constraints all deferred
And now the constraints are deferred, so we can insert data which still not inserted to the reference table.
insert into cons_deferrable_fk_tab values (1, 'one', 'foo');
Though commit will fail.
set constraints [Oracle SQL]
set constraint[s] all { immediate | deferred };
set constraint[s] constraint-name-1 [, constraint-name-n ...] { immediate | deferred };
分享到:
相关推荐
- **B) 不验证现有数据**:虽然题目中的选项B描述不完整,但实际上在启用一个带有`INITIALLY IMMEDIATE`子句的约束时,确实会对现有数据进行验证。如果存在违反约束的数据,那么启用约束的操作将会失败。 综上所述...
同时,他还分享了DEFERRABLE、INITIALLY DEFERRED、INITIALLY IMMEDIATE等的使用方式。 七、索引 董红禹分享了索引的使用方式,包括PostgreSQL中没有聚集索引、条件索引的创建方式等。同时,他还分享了索引的优化...
在表中定义了一个带有`INITIALLY IMMEDIATE`子句的约束后,这意味着: - 当创建表时,Oracle将立即尝试验证所有已存在的行是否符合新添加的约束条件。 - 如果表中有任何行不满足约束条件,则会在创建约束时抛出错误...
- **选项A:如果任何现有行违反该约束,则命令失败** - `INITIALLY IMMEDIATE`子句意味着约束立即生效,因此如果存在违反约束的数据行,则启用命令会失败。 - **未完全展示的选项** - 原文被截断,根据上下文推测,...
1. **A) 如果任何现有行违反了约束,则命令失败**:这是启用 INITIALLY IMMEDIATE 约束时的预期行为。如果存在违反约束的数据,那么命令将会失败。 2. **B) 不验证现有数据**:这与 INITIALLY IMMEDIATE 的行为...
DataGrid里面的执行分页删除 向数据库插入多条记录
在一个带有INITIALLY IMMEDIATE子句的约束上执行`ALTER TABLE`命令并启用验证选项会产生什么效果? **选项分析**: - A) 如果现有行违反了约束,则命令失败:正确,因为INITIALLY IMMEDIATE约束立即生效。 - B) 不...
The `INITIALLY IMMEDIATE` clause is used when creating constraints in Oracle to enforce them immediately rather than deferring until the end of the transaction. However, the question was cut off and ...
题目描述了一个带有 INITIALLY IMMEDIATE 子句定义的约束,并执行了 ALTER TABLE 命令以 ENABLE VALIDATE 选项启用被禁用的约束。 **知识点解析:** - **INITIALLY IMMEDIATE**:这意味着约束立即生效,而不是在...
- `ALTER TABLE table_name MODIFY CONSTRAINT constraint_name INITIALLY IMMEDIATE;`:修改约束的验证方式,立即验证约束有效性,确保数据的一致性。 - `ALTER SESSION SET CONSTRAINTS = DEFERRED / IMMEDIATE;`...
Li-Rich Vapor Transport Equilibration Temperature Dependence of Surface Composition of Initially Congruent LiNbO3 Crystal
SET CONSTRAINTS constraint_name {ENABLE | DISABLE} [INITIALLY IMMEDIATE | INITIALLY DEFERRED]; ``` - **示例**: ```sql SQL> set constraints cons_name disable; ``` #### 三、事务属性与操作 ##### ...
当表中定义了约束,并使用INITIALLY IMMEDIATE子句定义时,可以通过ALTER TABLE命令启用该约束: A) 如果任何现有的行违反了约束,则该命令失败(A):启用约束之前必须确保当前数据不违反该约束。 B) 启用约束后...
Unlike Windows search "Everything" initially displays every file and folder on your computer (hence the name "Everything"). You type in a search filter to limit what files and folders are displayed....
当使用 INITIALLY IMMEDIATE 子句定义约束并使用 ENABLE VALIDATE 选项启用约束时: - **选项 A:如果任何现有行违反了约束,则命令失败** — 启用约束时,Oracle 会检查表中现有的数据是否满足该约束条件。如果有...
Language, previously as Mathematica, in different fields: initially as an undergraduate, doing differential equations homework as a freshman, nuclear structure calculations, as a graduate student in ...
SSCERuntime-ENU sqlce 3.5 x64 x86
当使用`ALTER TABLE`命令启用一个之前禁用了的带有`INITIALLY IMMEDIATE`子句的约束条件时,需要注意以下几点: - **验证过程**:启用约束时,Oracle会验证现有数据是否符合该约束条件。如果不符,将会导致启用失败...
在LaTeX中处理中文文档时,常常会遇到一个挑战,那就是如何正确地生成包含中文书签的PDF文件。由于PDF的书签系统通常基于Unicode编码,而LaTeX默认使用的是西方字符编码,如ASCII,这可能导致在处理中文书签时出现...