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

求一更新sql语句,该怎么解决

2012-03-16 
求一更新sql语句现有2表ABA表idvalue1a23354f55B表idvalue1a3c5e现在我想把B表中的value更新到A表相应的id

求一更新sql语句
现有2表A   B
A   表
id   value
1       a
2       3
3       5
4       f
5       5

B   表
id   value
1       a
3       c
5       e


现在我想把B表中的value更新到A表相应的id之下,应该怎么做呢?
如果B表存在id> 6的数据A表能自动添加吗?

[解决办法]
update A set Value = B.Value from B where A.id=B.id
[解决办法]

现在我想把B表中的value更新到A表相应的id之下,应该怎么做呢?
==>
update A set Value = B.Value from B where A.id=B.id

如果B表存在id> 6的数据A表能自动添加吗?
\==>
不能,可以写个触发器实现

[解决办法]
同楼上
> 6 没关系 数据一样更新
[解决办法]
现在我想把B表中的value更新到A表相应的id之下,应该怎么做呢?
---------------------------------
update a
set value=b.value
from a inner join b on a.id=b.id
[解决办法]
我试了一下> 6是不能更新的,我觉得是不是写个not in 的insert会好一点?
update A set Value = B.Value from B where A.id=B.id
insert into A(id,Value)
select id, Value from B where id not in (select id from A) and id > 6

热点排行