Preface: What can you learn through this study
Directory:
One, what is a trigger.
second, what is the application scenario of the trigger.
1. Complex security Checks
2, the data confirmation
3. Realize audit function
4, the completion of data backup and synchronization
third, what is the syntax of triggers.
Iv. What types of triggers are available.
1, statement-level
The following articles mainly describe the detailed usage and case analysis of MySQL triggers. At the same time, this article also lists some code in the actual operations of MySQL triggers, the following is a detailed description of the article. Trigger case mysqlselect * froma; + ------ + | id | name | age | + ---
The following articles mainly describe the detailed usage and case analysis of MySQL
Creating triggers
Create a trigger with only one execution statementCREATE TRIGGER Trigger Name before| After Trigger eventOn table name for each ROW executes the statement where the trigger name parameter refers to the name of the trigger to be created
1. Create MySQL triggers:
Grammar:
The code is as follows
Copy Code
CREATE TRIGGER trigger_name trigger_time trigger_event o
One, trigger definition and creation:A trigger (trigger) is a special stored procedure whose execution is not invoked by the program or manually, but is triggered by an event, such as when an operation on a table (insert,delete,update) activates it for execution.Triggers can be created in Query Analyzer, or by right-click "All Tasks" and "Manage triggers" on the table name, but all are written in T-SQL statements, but in the Query Analyzer you first d
1. A trigger is a special stored procedure. It cannot be explicitly called. Instead, it is automatically activated when a record is inserted, updated, or deleted into the table. Therefore, triggers can be used to implement complex integrity constraints on tables.2. SQL Server creates two special tables for each trigger: The inserted Table and the deleted table. These two tables are maintained by the system and exist in the memory instead of in the dat
MySQL stored procedures and triggers use the explain Test table structure:
CREATE TABLE `a` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `cnt` INT(11) NULL DEFAULT NULL, PRIMARY KEY (`id`))COLLATE='utf8_general_ci'ENGINE=MyISAMROW_FORMAT=DEFAULT
Several permissions related to stored procedures:
alter routine,create routine,execute
Permissions related to triggers:
trigger
Create a test
Triggers in MySQLTrigger
Requirements: There are two tables, an order form, a commodity table. Each order is generated, the inventory of goods is reduced accordingly.
Trigger (Trigger)
Binding a piece of code in advance for a table, and when something changes (or additions or deletions), the system automatically triggers the execution of the code.
Label:SQL Server triggers A trigger is a special stored procedure that is triggered only when you attempt to modify data using the data manipulation language DML, which contains the add, delete, and change of the view and table. Triggers are divided into DML triggers and DDL triggers, where DML
Reprint Address: http://www.2cto.com/database/201212/176781.htmlA trigger is a MySQL statement (or a set of statements between the begin and end statements) that is automatically executed by MySQL in response to any of the following statements: www.2cto.com delete; insert; NB Sp update; The use of triggers requires MYSQL5 or later version support. First, trigger basic operations 1, create trigge
In-depth analysis of SQL Server triggers and SQL
A trigger is a special type of stored procedure, which is different from the stored procedure we introduced earlier. 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.
Ø what is a trigger?
A special stored procedure that is automatically executed when a trigger inserts, updates, or deletes a table.
The following articles mainly describe how to use MySQL triggers correctly. MySQL Databases reference MySQL triggers in Versions later than 5.0, sometimes, you can use related triggers to maintain data integrity. For example, I have a table ge_element. This table has a region_id that corresponds to the id in the ge_region table. However,
The following articles ma
. So the example here will run normally on your computer. However, if the operation still fails, you can consult a senior MySQL user you know so that you can get better support and help.
Why does why triggers Use Triggers?
The reason why we support triggers in MySQL 5.0 is as follows:
Users of earlier MySQL versions have long-term requirements for triggers.W
Develop PL/SQL subprograms and packages, write triggers using PL/SQL, and Apply Oracle and pljdbc to JDBC.
1. subprograms:
Declaration, executable, and Exception Handling (optional)
2. subprogram classification:
A. Process-execute some operations
A. syntax of the creation process:
CREATE [or replace] PROCEDURE
BEGIN
[EXCEPTION
END;
B. Three Modes of process parameters:
IN: Used to accept the value of the calling program, default parameter Mode
OUT
Test Table Structure:
CREATE TABLE `a` ( `id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `cnt` INT(11) NULL DEFAULT NULL,PRIMARY KEY (`id`))COLLATE='utf8_general_ci'ENGINE=MyISAMROW_FORMAT=DEFAULT
Several permissions related to stored procedures:
alter routine,create routine,execute
Permissions related to triggers:
trigger
Create a test account:
grant select,update,insert,create,delete,trigger,alter routine,create routine,execute on test.* to 'my
Creating triggersCreate a trigger with only one execution statement
Copy Code code as follows:
CREATE TRIGGER Trigger Name before| After Trigger event
On table name for each ROW EXECUTE statement
Where the trigger name parameter refers to the name of the trigger to be created
The Before and after parameters specify when the execution is triggered, before or after the event
For each row indicates that an action on any record that satisfies a trigger event
is deleted from the Categories table). All affected products are labeled 1 and are no longer used for these products.
Use Northwind
CREATE TRIGGER Category_delete
On Categories
For DELETE
As
UPDATE P SET discontinued = 1
From the products as P INNER JOIN deleted as D
On P.categoryid = D.categoryid
The work process of the update trigger
You can consider an UPDATE statement as a two-step operation: A DELETE statement that ca
Tags: SQL database Why storage research Cancel begin change pass name A trigger (trigger) is a special stored procedure whose execution is not invoked by the program or manually, but is triggered by an event, such as when an operation on a table (Insert,delete, update) activates it for execution. Triggers are often used to enforce data integrity constraints, business rules, and so on. Triggers can be
; Xxx.sql② Export multiple table structures and datamysqldump-b dbname1--tables tablename1 tablename2-u root-p > Xxx.sql———————————— – Stored Procedure function Operations ————————————-7. Export only stored procedures and functions (do not export structure and data, you need to use-D at the same time to export the structure)mysqldump-r-ndt dbname1-u root-p > Xxx.sql———————————————-Event Action ———————————————-8. Export only Eventsmysqldump-e-ndt dbname1-u root-p > Xxx.sql————————————— – Trigger
dataMysqldump-b dbname1--tables tablename1 tablename2-u root-p > Xxx.sql———————————— – Stored Procedure function Operations ————————————-7. Export only stored procedures and functions (do not export structure and data, you need to use-D at the same time to export the structure)Mysqldump-r-ndt dbname1-u root-p > Xxx.sql———————————————-Event Action ———————————————-8. Export only EventsMYSQLDUMP-E-ndt dbname1-u root-p > Xxx.sql————————————— – Trigger Action —————————————— –9. Do not export
Introduction:A trigger is actually a special kind of stored procedure. It only operates on its own initiative when a particular event occurs.Stored procedures and triggers are a collection of SQL statements and Process Control statements that are called directly by the name of the stored procedure. The trigger is run mainly by time.categories of triggers:Triggers contain DML triggers and DDL
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.