create table t( id number(11), name varchar2(30) );create unique index id_text_t on T (id) tablespace data_model_log;insert into t (ID, NAME) values ('3', 'li');insert into t (ID, NAME) values ('6', 'zhang');insert into t (ID, NAME) values ('7', 'shao');--批量修改 update t set t.id = id+1 where id >3 commit; 如果是批量用sql修改的话,oracle是支持的
唯一索引:create table t( id number(11), name varchar2(30) );
create unique index id_text_t on T (id) tablespace data_model_log;
insert into t (ID, NAME) values ('3', 'li');
insert into t (ID, NAME) values ('6', 'zhang');
insert into t (ID, NAME) values ('7', 'shao');
--批量修改 update t set t.id = id+1 where id >3 commit;--之后执行 update t set t.id =6 where id = 3;---这个违反唯一性了。 update t set t.id =8 where id = 6; commit;能否在commit;时才进行校验。
只能倒着写了 update t set t.id =8 where id = 6; update t set t.id =6 where id = 3;---这个违反唯一性了。 commit; 先把没有违反唯一性的写在前面 违反唯一性的放在其后面。
create table t(
id number(11),
name varchar2(30)
);create unique index id_text_t on T (id) tablespace data_model_log;insert into t (ID, NAME)
values ('3', 'li');insert into t (ID, NAME)
values ('6', 'zhang');insert into t (ID, NAME)
values ('7', 'shao');--批量修改
update t set t.id = id+1 where id >3
commit;
如果是批量用sql修改的话,oracle是支持的
id number(11),
name varchar2(30)
);
create unique index id_text_t on T (id) tablespace data_model_log;
insert into t (ID, NAME)
values ('3', 'li');
insert into t (ID, NAME)
values ('6', 'zhang');
insert into t (ID, NAME)
values ('7', 'shao');
--批量修改
update t set t.id = id+1 where id >3
commit;--之后执行
update t set t.id =6 where id = 3;---这个违反唯一性了。
update t set t.id =8 where id = 6;
commit;能否在commit;时才进行校验。
update t set t.id =8 where id = 6;
update t set t.id =6 where id = 3;---这个违反唯一性了。
commit;
先把没有违反唯一性的写在前面
违反唯一性的放在其后面。
按你的例子,a有两条记录,1和2,建唯一约束,这1和2应该是类似ID的东西,理论上只会更新它们的属性,而不会更新它们的ID。如果要变成2和3,应该是删除1,新增3,这么一个操作
这个需求我很怀疑设计是否严谨。如果还是需要的话,唯一约束不能满足这个需求,你可以通过程序来判重