我有三张桌子:
Customer: Id, FirstName, LastName, Email
CommunityUser: Id, FirstName, LastName, Email , CustomerId
BlogComment: Id, CustomerId, Text
如何使用T-SQL为每个BlogComment.CustomerId
设置相应的CommunityUser.Id
我试过了:
For select * from BlogComment bc
update bc set CustomerId = (select cu.Id from CommunityUser cu Where cu.CustomerId = bc.CustomerId)
但它不是有效的语法
答案 0 :(得分:1)
加入CommunityUser的简单更新将有助于
Update B
set b.Customerid = cu.id
from BlogComment b inner join CommunityUser cu
on b.Costumerid = cu.CustomerId
答案 1 :(得分:0)
update BlogComment bc
set CustomerId = (select Id from CommunityUser cu Where cu.CustomerId = bc.CustomerId)
答案 2 :(得分:0)
试试
UPDATE bc
SET bc.CustomerId = cu.Id
FROM CommunityUser cu INNER JOIN BlogComment bc
ON cu.CustomerId = bc.CustomerId