insert,update trigger
Hey!
I have a problem using "for insert, update" -style trigger. It works nicely with table updates but inserts do not seem to work. Here is a sample of the trigger:
CREATE TRIGGER customer_trigger ON dbo.CUSTOMER FOR INSERT, UPDATE AS BEGIN DECLARE @col_name varchar(30),@old_value varchar(80),@new_value varchar(80) SELECT @col_name = 'NAME',@old_value = del.NAME,@new_value = ins.NAME FROM deleted del, inserted ins IF @new_value<>@old_value BEGIN INSERT INTO HISTORY_TABLE(FIELD,OLDVALUE,NEWVALUE,TIME) SELECT @col_name,@old_value,@new_value,getDate() FROM deleted del, inserted ins END END
I haven't worked with triggers much so I appreciate all the help I can get.
|