Trigger design skills and instances
In the database design, there are two ways to automate the data processing rules, one is the conditional constraint, one is a trigger, in general, the conditional constraint is easier to set and maintain than the trigger, and the execution efficiency is more Ok, but the conditional constraint can only be used to make a simple field queue. When it comes to multi-table operation, it is necessary to use the trigger. There are two virtual tables in a database system to store in the table. Information recorded in the record, namely: Virtual Table INSERTED Virtual Table Deleted
When the new record is stored in the new record, the record is stored when the new record is stored when the new record is stored, the record is stored, and the record trigger is not stored. The type and trigger timing of the recorded recording trigger and trigger the AFTER trigger: trigger After the time is changed, it will make the necessary goodness and processing of the change data. If there is an error, the ROLLBACK TRANSACTION will reply all the operations fifted by this operation. Istead of trigger: Trigger time occurs before the data changes, and how data changes depend on the trigger
Now introduce the format of the creation of the trigger:
AFTER Type: CREATE TRIGGER Trigger Name ON Name After Operation (Insert, Update) AS SQL Statement
INSTEAD Type Create Trigger Trigger Name ON Name INSTEAD OF Action (Update, Delete) AS SQL Statement
Example 1: When there is a change in the order (Name Num) in the order (column name NUM), the trigger will be able to get the user's credit level (column name Level) first to the customer (list Customer), and then go to The order quantity up and lower limit of the order license is taken in the credit limit (Creit), and the order quantity in the order is compliant.