Mega Code Archive

 
Categories / MSSQL Tutorial / Trigger
 

One table with two after-delete triggers

3>  CREATE TABLE test_trigger 4> (col1 int, 5>  col2 char(6) ) 6> GO 1> INSERT INTO test_trigger VALUES (1, 'First') 2> INSERT INTO test_trigger VALUES (2, 'Second') 3> INSERT INTO test_trigger VALUES (3, 'Third') 4> INSERT INTO test_trigger VALUES (4, 'Fourth') 5> INSERT INTO test_trigger VALUES (5, 'Fifth') 6> GO 1> 2> CREATE TRIGGER delete_test 3> ON test_trigger AFTER DELETE 4> AS 5> PRINT 'You just deleted a row!' 6> GO 1> 2> ALTER TRIGGER delete_test 3> ON test_trigger AFTER DELETE 4> AS 5> IF @@ROWCOUNT = 0 RETURN 6> PRINT 'You just deleted a row!' 7> GO 1> 2> DELETE test_trigger 3> WHERE col1 = 0 4> GO 1> 2> drop table test_trigger; 3> GO 1>