I want to check a Column value when update.If its match insert into another table.
My Tables:

My trigger:
CREATE TRIGGER tr_test
ON test1
FOR UPDATE
AS
SET nocount ON
IF ( Update(sname) )
DECLARE @Name NVARCHAR
DECLARE @id INT
SET @id=@@IDENTITY
SET @Name=(SELECT sname
FROM test1
WHERE id = @id)
IF( @Name = 'Paras' )
BEGIN
INSERT INTO test2
(loginfo)
VALUES ('success')
END
And my update query is:
update Test1 set Sname='Paras' where ID=1
When I run this update query Nothing is happen.Test2 table is empty.I think problem is @@IDENTITY but not sure.Thanks.
Try this:
But it’s better to do this, an update can update many rows, the above will fail if UPDATE matches many rows, use EXISTS:
insertedtable is the name of the table where the UPDATE’s new values goes,deletedtable is the name of the table where UPDATE’s old values goes