日期:2014-05-18  浏览次数:20378 次

求:更新语句,两个表
A表
id           name       tt
1               2             2
2               3             3
3               4             2

B表
id           tt
1             2
2
3
我现在需要由A表关联,更新B表tt列的数值
这样的sql语句怎么写,谢谢!

------解决方案--------------------
是这样把!!!!!

update B
set tt= A.tt
from A ,B
where B.id =A.id


------解决方案--------------------
-- 看这个测试?是不是?

create table A (id INT,name varchar(10),tt int )
insert A
select 1 , '2 ', 2
union all select 2 , '3 ', 3
union all select 3 , '4 ', 2
go
create table B (id int,tt int )
insert B
select 1 ,null
union all select 2 ,null
union all select 3 ,null


update B
set tt= A.tt
from A ,B
where B.id =A.id
/*

id tt
----- -----
1 2
2 3
3 2

*/

DROP TABLE A

DROP TABLE B
------解决方案--------------------
楼主的问题跟这个很相似,试试触发器
http://community.csdn.net/Expert/topic/5729/5729842.xml?temp=.2835504