Table for INSTEAD OF Trigger for Logical Deletes : Trigger « Trigger « SQL Server / T-SQL Tutorial






4>
5> CREATE TABLE MyTable
6> (
7>   ID  int      NOT NULL PRIMARY KEY,
8>   del char (1) NOT NULL DEFAULT 'N'
9> )
10> GO
1>
2> --INSTEAD OF Trigger for Logical Deletes
3> CREATE TRIGGER trd_MyTable ON MyTable INSTEAD OF DELETE
4> AS
5> IF @@ROWCOUNT = 0
6>   RETURN
7> UPDATE M
8> SET
9>   del = 'Y'
10> FROM
11>     MyTable AS M
12>   JOIN
13>     deleted AS D ON D.ID = M.ID
14> GO
1>
2> drop table mytable
3> GO








22.1.Trigger
22.1.1.The syntax of the CREATE TRIGGER statement
22.1.2.exits if the price column has not been updated.
22.1.3.Define variables in a trigger
22.1.4.Update table in a trigger
22.1.5.Check @@ROWCOUNT in a trigger
22.1.6.Rollback transaction in a trigger
22.1.7.RAISERROR in trigger
22.1.8.Disable a trigger
22.1.9.Enable a trigger
22.1.10.Check business logic in a trigger
22.1.11.Check record matching in a trigger
22.1.12.Table for INSTEAD OF Trigger for Logical Deletes
22.1.13.INSTEAD OF INSERT trigger for a table
22.1.14.Trigger Scripts for Cascading DELETEs