Trigger Insert Update Delete
Create TRIGGER trgTransactions on dbo.test1 AFTER INSERT, DELETE, UPDATE
AS
BEGIN
DECLARE @DeletedId INT, @InsertId int
SELECT @InsertId = Test from inserted
SELECT @DeletedId= Test from Deleted
IF (@InsertId > 0 AND isnull(@DeletedId,'') = '')
BEGIN
--DELETE FROM TomsWebDBNProdV2_clone_test.dbo.test1 where Test = @InsertId
INSERT INTO TomsWebDBNProdV2_clone_test.dbo.test1
SELECT * FROM INSERTED
END
-- insert
IF (@InsertId > 0 AND @DeletedId > 0)
BEGIN
DELETE FROM TomsWebDBNProdV2_clone_test.dbo.test1 where Test = @InsertId
INSERT INTO TomsWebDBNProdV2_clone_test.dbo.test1
SELECT * FROM INSERTED
END
-- update
IF( isnull(@InsertId,'') = '' AND @DeletedId > 0)
-- delete
DELETE FROM TomsWebDBNProdV2_clone_test.dbo.test1 where Test = @DeletedId
END
Labels: AFTER INSERT, DELETE, Update