私は2つのテーブルを持っています:
usersuser_id, statusカラム付きchangesuser_id, type列のある
から行を削除したいchanges場合type = 5は、次を設定します。
users.status = NULL Where users.user_id = changes.user_id
どうすればいいですか?
私は2つのテーブルを持っています:
usersuser_id, statusカラム付きchangesuser_id, type列のあるから行を削除したいchanges場合type = 5は、次を設定します。
users.status = NULL Where users.user_id = changes.user_id
どうすればいいですか?
これを試して:
-- 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);