I’ve got problem with INSTEAD OF trigger in MsSQL. I got an app with some error, and as a quick workaround I don’t want user to modify one exact row in DB.
I created following trigger: (on table)
create trigger UglyWorkaround ON Configuration instead of update
as
begin
if (select COUNT(1) from inserted where Key='Key01' and Value<>'2') > 0 begin
update Configuration set Value='2' where Key='Key01'
end else begin
-- DEFAULT ACTION (do update as intended)
end;
end;
But I’ve got problem with determining, how to set default action.
Update Configuration set Value=inserted.Value where Key=inserted.Key doesn’t work for me. Is there any way how to do this with triggers? (I know that the solution is bad, but I got no other option, as I can’t change code now.)
insertedis a table, so try joining:You could also filter out
Key01at the same time, and it wouldn’t matter if they tried to update the value forKey01to something other than2.