What are the disadvantages and advantages of defining a constraint

We use the Oracle database in our projects. And we define so many constraints that can be applied to the database (including primary, unique, control, and external key constraints).

It seems that the defining DEFERRABLE constraints allow us to DEFER them when required, so why should any constraint be defined as NOT DEFRASHABLE?

Why are databases such as Oracle not DEFERRABLE as default cases?

Are there any pros to define a NOT DEFERRABLE constraint?

+4
source share
1 answer

, , DML , .

:

create table parent
(
   id integer not null primary key
);

create table child
(
  id integer not null primary key,
  parent_id integer not null references parent
);

create table grand_child
(
  id integer not null primary key,
  child_id integer not null references child
);

, ( ) ( ) , , , . , / , , .

, ( !) :

insert into grand_child values (1,1);
insert into child values (1,1);
insert into parent values (1);
commit;

, .

:

create table one
(
   id integer not null primary key,
   id_two integer not null
);

create table two
(
   id integer not null primary key
   id_one integer not null
);

alter table one add constraint fk_one_two (id_two) references two(id);
alter table two add constraint fk_two_one (id_one) references one(id);

.

, , , fk . :

(1, null); (1, 1); set id_two = 1 id = 1;

.

( , , !)

, , .

. , commit, . , , . insert ( delete update), , .

+6

All Articles