i want to do something like that; if someone tries to update a table, the trigger will fire and add a new record that contains the field name, old value and new value.
i have already done a small part of it.
the code is below.
Expand|Select|Wrap|Line Numbers
- set ANSI_NULLS ON
- set QUOTED_IDENTIFIER ON
- GO
- ALTER TRIGGER [dbo].[forumchange] ON test2
- FOR UPDATE
- AS
- BEGIN
- Declare @newNAME varchar(64)
- Declare @oldNAME varchar(64)
- declare @date datetime
- Select @oldNAME = ad from deleted
- Select @newNAME = ad from inserted
- select @date = getdate()
- if (@newNAME is not null) and (@oldNAME is not null)
- insert into test3 (oldNAME,newNAME,date)
- values (@oldname,@newname,@date)
- END
but current code only controls the "name" field of the table name_surname.
i want it to go after every field and log them.
thank you.