Database Operations--triggers

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.