# 表与表之间的更新问题

A表字段有a,b,c,d,e有数据
B表字段有a,b,c有大量数据

...全文
70 点赞 收藏 15

15 条回复

Limpire 2008-04-06
1是什么意思
--------------------
1就是1，常量，如：
``select 1,* from sysobjects``

insert into A(a,b,c)
select a,b,c from B where A.a!=B.a
-------------------

``````insert into A(a,b,c)
select y.* from B as y left join A as x on y.a=x.a where x.a is null
``````

q520525745 2008-04-06
insert into A(a,b,c)
select a,b,c from B where A.a!=B.a

q520525745 2008-04-06
[Quote=引用 9 楼 Limpire 的回复:]
(select 1 from A where a=y.a)
[/Quote]

Limpire 2008-04-06
``````--用别名
update x set x.b=y.b,x.c=y.c from A as x join B as y on x.a=y.a
insert A(a,b,c) select * from B as y where not exists (select 1 from A where a=y.a)
``````

Limpire 2008-04-06
``````update A set A.b=B.b,A.c=B.c from A join B on A.a=B.a
insert A(a,b,c) select * from B where not exists (select 1 from A where a=B.a)``````

q520525745 2008-04-06

Limpire 2008-04-06
``````update a set a.b.=b.b,a.c=b.c from a join b on a.a=b.a

insert a(a,b,c) select * from b where not exists (select 1 from a where a=b.a)
``````

q520525745 2008-04-06

piaoqifeng 2008-04-06

B中有A中相同的，如果A中相同的有多条呢，如何处理

piaoqifeng 2008-04-06
insert into a(a,b,c)
select a,b,c from b
where a+b+c not in
(select a+b+c from a)

3.3w+

MS-SQL Server相关内容讨论专区