I want to trigger an update on a specifc column, when changed.
(history: some application does an update on a column, and I cant find what app. Therefore I decieded to make a trigger to force back the value).
To make it simple..
UsrTbl:
usrid usr pwd
1001 admin qwerty
2001 cto demo
3001 ceo demo
...
if someone makes an update on pwd where usr is admin, I want to re-update it to specific value.
If i do a trigger, something like:
CREATE TRIGGER the_usr_trg ON usrtbl AFTER UPDATE AS
UPDATE usrtbl SET pwd='qwerty' WHERE usr = 'admin'
GO
Will above fix this for me?
What happen when the trigger updates the column? will it fire the_usr_trg trigger again ? will this cause a loop in the database server? or will it run once only?
Is there better approach to fix this? (other than finding what app is updating this column:)
Thank you!
I believe that it will depend on the recursion level for triggers that is on the DB. If the
RECURSIVE_TRIGGERSis setted toOFF, then it will be run only once. In your case, think that it would be better if you create anINSTEAD OFtrigger, thus avoiding the firstUPDATEon your table. In your case it would be something like this: