MS SQL Basics Tutorial: Application of Triggers

Source: Internet
Author: User

In the above section we discuss the pros and cons of triggers, how they work, and how to create triggers. Next we will elaborate on the application of triggers of varying degrees of complexity.

Application of 12.9.1 Insert-type Trigger

Application of 12.9.1 Insert-type Trigger

There are two types of newer triggers: Newer triggers in common sense and newer triggers for checking column changes, mainly because update operations can involve data items.

More new triggers in the usual sense;

As we mentioned earlier, the update operation consists of two parts, first removing the content that needs to be updated from the table, and inserting the new value. As a result, newer triggers involve deleting tables. and insert the table below the combination of specific examples to discuss it.

In some updates, the updated content is not an entire record, but only a column or columns, and a newer trigger for checking column changes is used. It differs from the usual trigger in the sense that it includes the following reserved words:

In the part of creating a trigger with the Transaction_sql Create TRIGGER command We have given the specific meaning of the reserved word. Below we will give two examples, these two examples are used in the If UPDATE (column) and if (columns_updated () respectively.

Note: You must first delete the relationships with the primary foreign key that the table title has established before the trigger can be triggered.

12.9.4 nested triggers

When a trigger executes, it can trigger another trigger, which is called a trigger nesting. Triggers can be nested to 32 levels in MS SQL Server. If you do not need nested triggers, you can set them by using the sp_configure option.

During execution, if a trigger modifies a table, and the table already has other triggers, it is necessary to use nested triggers.

Note: The primary foreign key relationships that have been established with the sales table must be deleted before triggers can be triggered.

See the full set of "MS SQL Basics Tutorials"

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.