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

再来一贴:sql server如何更新两张表的内容?
在access中可以正常运行,但SQL SERVER就不行了,update后不支持两个表名,下面的语句怎样写才正确呢?

SQL="update 留言,user set 留言.交易地点=‘广州’,user.自己物品='手机' where 留言.排序='"& getid &"' and 留言.用户名=user.登陆用户名"

------解决方案--------------------
SQL code

--变成2条,貌似是这样的
update  留言
set     交易地点 = '广州'
from    留言 a
        left join [user] b on a.用户名 = b.登陆用户名
where   b.登陆用户名 is not null
        and a.排序 = @getid
        
update  [user]
set     自己物品 = '手机'
from    [user] b
        right join 留言 a on a.用户名 = b.登陆用户名
where   b.登陆用户名 is not null
        and a.排序 = @getid

------解决方案--------------------
SQL code
update b set b.自己物品='手机'
from 留言 a,user b
where a.用户名=b.登陆用户名
and a.排序='getid'

update 留言 set 留言.交易地点=‘广州’
where 
 排序='getid'

------解决方案--------------------
触发器