1

我有两张桌子:

  1. usersuser_id, status柱子
  2. changesuser_id, type

我想从changes和 if中删除一行type = 5,然后设置:

users.status = NULL Where users.user_id = changes.user_id

我该怎么做?

4

2 回答 2

2

尝试这个:

-- table variable to store deleted changes
declare @deleted_changes table(user_id int, [type] int);

-- saving info from deleted changes into temp table
delete from changes 
output deleted.user_id, deleted.[type] into @deleted_changes;
-- where [some condition]

-- updating users only if corresponding changes with type = 5 were deleted
update users
set status = null
where user_id in (select user_id from @deleted_changes where [type] = 5);
于 2013-11-10T15:05:21.297 回答
0

对于DELETE,你的意思是...

DELETE FROM Changes WHERE type = 5

尝试以下更新....

UPDATE  u
SET     u.status = NULL
FROM    users u
        INNER JOIN changes c ON u.user_id = c.user_id
于 2013-11-10T14:58:46.947 回答