A trigger is a special type of stored procedure that differs from stored procedures in that the trigger is executed automatically by an event, and stored procedures can be called by the name of the stored procedure.
Triggers are divided into
1. After trigger
2. Insert Trigger
3. Update Trigger
4. Delete Trigger
A trigger is a stored procedure that is automatically executed when a table is inserted, updated, and deleted. Although the function of the trigger is powerful, it can implement many complex functions easily and reliably, but too much trigger will make the database and application maintenance difficult, and the excessive dependence on the trigger will affect the structure of the database, and add the complicated program of maintenance.
In the beef Brisket news release system, the use of the next trigger is learned, and when the data in the table is deleted, the data in the other tables is deleted, and then the data in the table is deleted.
<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" >use [newssystem]go/****** Object: Trigger [dbo].[ Trigcategorydelete] Script date:2015/2/8 22:48:11 ******/set ansi_nulls ongoset quoted_identifier ONGO--========= ====================================--Author: Mashu--Create date:2015-2-4--Description: Delete Category trigger--================== ===========================alter TRIGGER [dbo]. [Trigcategorydelete] On [dbo].[ Category] instead of Deleteas begindeclare @caId intselect @caId =id from deleted--Delete comment Delete comment where newsId in ( Select NewsId from news where [email protected]--delete news, delete, and where [email protected]--delete category Delete categories where [EMA Il protected]end</span>
the use of this trigger, found that the trigger is the same as the view and stored procedures, are not as difficult as imagined. Triggers should also have a bigger role, now just the equivalent of a simple understanding, I believe later with it will have a greater effect.
Database Operations--triggers