Database Operations-triggers, databases-triggers
A trigger is a special type of stored procedure. Unlike a stored procedure, a trigger is triggered by an event and automatically called for execution, the stored procedure can be called by the name of the stored procedure.
Trigger
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, or deleted. Although the trigger functions are powerful and easy to implement many complex functions, too many triggers may make it difficult to maintain databases and applications, and excessively dependent on the trigger, will affect the structure of the database, while adding a complex program for maintenance.
I learned how to use the trigger in the niugu news publishing system. When deleting the data in the table, I first Delete the data in other tables and then delete the data in the table.
<Span style = "font-family: KaiTi_GB2312; font-size: 18px;"> USE [newssystem] GO/****** Object: Trigger [dbo]. [trigCategoryDelete] Script Date: 22:48:11 *****/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO -- ================ =================================-- Author: ma shichao -- Create date: 2015-2-4 -- Description: delete A category trigger -- ========================================== ========= alter trigger [dbo]. [trigCategoryDelete] ON [dbo]. [category] instead of deleteAS BEGINdeclare @ caId intselect @ caId = id from deleted -- delete comment where newsId in (select newsId from news where caId = @ caId) -- delete news delete where caid = @ caId -- delete category where id = @ caIdEND </span>
With this trigger, it is found that the trigger is not as difficult as you think as the view and stored procedure. The trigger should have a greater role. Now it is just a simple understanding. I believe it will play a greater role in the future.