I have a trigger which was developed for single row updates, but it needs to handle multi-row updates to support 2005. The basis of the trigger is that it does a value comparison on a specific field to see if it changed and then reacts based on the change.
Example:
CREATE TRIGGER check_for_change
ON mytable FOR INSERT, UPDATE, DELETE
AS
DECLARE
@old_key VARCHAR(20),
@new_key VARCHAR(20)
BEGIN
SELECT
@old_key = del.key
FROM deleted del
SELECT
@new_key = ins.key
FROM inserted ins
IF( NOT(@old_key = @new_key)
BEGIN
Do something ...
END
END
Can anyone give me some pointers on how to accomplish this? Also it would be great if I could also get a recommendation for a book which would help me with the multi-row update concept in the future.
Any help would be appreciated.
Thanks!
Example:
CREATE TRIGGER check_for_change
ON mytable FOR INSERT, UPDATE, DELETE
AS
DECLARE
@old_key VARCHAR(20),
@new_key VARCHAR(20)
BEGIN
SELECT
@old_key = del.key
FROM deleted del
SELECT
@new_key = ins.key
FROM inserted ins
IF( NOT(@old_key = @new_key)
BEGIN
Do something ...
END
END
Can anyone give me some pointers on how to accomplish this? Also it would be great if I could also get a recommendation for a book which would help me with the multi-row update concept in the future.
Any help would be appreciated.
Thanks!