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

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

2012-01-12 
求:更新语句,两个表A表idnamett122233342B表idtt1223我现在需要由A表关联,更新B表tt列的数值这样的sql语句

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

热点排行
Bad Request.