my update trigger is as below .
CREATE TRIGGER [dbo].[tb_sample_UpdationTrigger] on [dbo].[tb_sample] for UPDATE
as
if UPDATE(R_Id)
insert into dbo.test_log(Attribute,Action,OldValue,NEwValue,UserId,ModifiedDate)
(SELECT 'R_Id','update',tb_sample.R_Id,inserted.R_Id ,1,GETDATE()
from inserted
inner join tb_sample on inserted.id =tb_sample.id)
. I update the R_Id from 100000 to 200000 . But record inserted to the log table is
R_Id update 200000 200000 1 2012-01-20 12:38:16.730
If we see the old value and new value both are 200000 .
Wats wrong here ?
If you want to get the old value you have to use the
deletedspecial table, since an update can be seen as a delete and an insert action. See: Using the inserted and deleted Tables. So your select should look like (untested):