首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > SQL Server >

求2表数据比较sql,该如何处理

2012-03-13 
求2表数据比较sqlsqlserver20002章表的数据结构相同现在需要将A表数据跟B表数据做比对当发现A中某一字段的

求2表数据比较sql
sqlserver2000

2章表的数据结构相同

现在需要将A表数据跟B表数据做比对

当发现A中某一字段的值在B中已经出现,则将A中该条记录整体更新到B中;当发现B中没有该记录时,则将A中该条记录插入B中

[解决办法]

SQL code
delete A from B,A where A.某一字段=B.某一字段insert into B select * from A  where not exists(select 1 from B where 某一字段=A.某一字段)
[解决办法]
SQL code
--delete Bdelete B from B,A where A.某一字段=B.某一字段insert into B select * from A  where not exists(select 1 from B where 某一字段=A.某一字段)
[解决办法]
+1
探讨
SQL code

--delete B
delete B from B,A where A.某一字段=B.某一字段
insert into B
select * from A
where not exists(select 1 from B where 某一字段=A.某一字段)

[解决办法]
SQL code
update b set col1=a.col1 .... from a join b on a.关联字段=b.关联字段 insert into b select * from a where not exists(select 1 from b where 关联字段=a.关联字段) 

热点排行