想将表A中的数据拷贝到表B中去。
B设有主键,而且有一部分数据。
insert into B select * from a;
但是遇到主键冲突时,就会报错,可以设置一下,让sql忽略这条错误,继续将下一条数据往B中拷贝吗?
谢谢。
B设有主键,而且有一部分数据。
insert into B select * from a;
但是遇到主键冲突时,就会报错,可以设置一下,让sql忽略这条错误,继续将下一条数据往B中拷贝吗?
谢谢。
alter table b disable constraint 主键名称;
来禁用约束
B设有主键,而且有一部分数据。
insert into B select * from a;
但是遇到主键冲突时,就会报错,可以设置一下,让sql忽略这条错误,继续将下一条数据往B中拷贝吗?
谢谢。insert into b
select * from a
where not exists ( select 1 from b where b.col1=a.col1,...b.coln=a.coln );
select * from a
where not exists ( select 1 from b where b.pk_column=a.pk_column );-- pk_column 表示是主键字段!
示例:merge into t_table t
using(select id,name,age,re,t_id from t_table_1) t1
on(t.id=t1.id)
when matched then
update set t.name=t1.name,t.age=t1.age,t.re=t1.re,t.t_id=t1.t_id(需要更新字段)
when not matched then insert (t.id,t.name,t.age,t.re,t.t_id)
values(t1.id,t1.name,t1.age,t1.re,t1.t_id)