用join和where更新两个表 [英] update two tables with join and where

查看:85
本文介绍了用join和where更新两个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


使用join和where条件更新两个表

我需要两个表更新并具有1个条件.示例table1和table2具有1个条件.

如何编写查询?

任何想法!

我的查询出现此错误.如何修改查询?



Hi,
update two tables with join and where condition

i need two tables update and with 1 condition. Example table1 and table2 with 1 condition.

how write query?

any idea!

i get this error for my query.Here how to modified query?



update ps set 
PurposeOfVisit=@purposeofvisit,
   p.IsBanned=@isbanned
   from [PersonSessions] ps
   inner join person as p on p.id=ps.visitorid
   where ps.Id = @id



在这里传递类似该字段的值.



Here pass the value like that field.

update ps set
PurposeOfVisit='interview',
   p.IsBanned=false
   from [PersonSessions] ps
   inner join person as p on p.id=ps.visitorid
   where ps.Id = 4



如何使用条件



how to update two tables join with where condition

推荐答案

,我认为不可能用单个update语句更新两个表.您可以创建过程并更新多个表或创建触发器.您还可以使用事务并确保两个表数据都正确更新.
i think it is not possible to update two tables with single update statement. You can create procedure and update multiple tables or create triggers. You can also use transactions and can make sure that both table data is updated correctly.


这篇关于用join和where更新两个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆