日期:2014-05-17  浏览次数:20696 次

SQL语句错误
假设表A得结构为A(   a,b,c,d   )表B得结构为B(a,c,d,e,f),并且(a,c)构成了A的主键;A表中的部分数据已经导入到B表
要求:将A表中未导入B表的数据继续导入;已经导入的不能再次执行,否则会造成(a,c)值有在表B中不唯一。

下面是我写的语句,有错误
Insert   into   B(   a,c,d   )   select   a,c,d   from   A   where   a!=B.a   or   c!=B.c

请教高手该怎么修改



------解决方案--------------------
Insert into B( a,c,d )
select a,c,d from A
where not exists
(select * from B where a!=A.a and c!=A.c)
------解决方案--------------------
Insert into B( a,c,d )
select a,c,d from A
where not exists
(select * from B where a=A.a and c=A.c)
------解决方案--------------------
tinayacao007的是对的,上面那个逻辑上错误了。