I am working on triggers in sql. I am trying to do an update trigger, however I want it to work only if a certain condition is met.
For example lets say I have a table X and two columns A,B.
I want to be able to update A or B only when A is less than B for the new values to be updates.
So I am doing a trigger like this
create trigger utrigger
on X
for update as
if (update(A) OR update(B))
begin
if (A>B)
RAISERROR (N' Incorrect %s %d.', -- Message text.
10, -- Severity,
1, -- State,
N'number', -- First argument.
5); -- Second argument.
end
However I think I am doing it wrong. Whats wrong in this?
You need to use the INSERTED virtual table.