读书人

求:更新语句两个表解决思路

发布时间: 2012-01-12 22:11:58 作者: rapoo

求:更新语句,两个表
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

读书人网 >SQL Server

热点推荐