.Net Basic

This blogs gives introduction to C#.NET programming for beginners. This blogs assumes that you have no programming experience whatsoever. It's a lot easier than you think, and can be a very rewarding hobby!after Refer this blog

04 April 2012

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: , ,