Different syntax for MySQL and SQL triggers _ MySQL

Source: Internet
Author: User
Use bitsCN.com as the trigger for MySQL and SQL

TriggerIt is often used to strengthen data integrity constraints and business rules. It is often used in MySQL and SQL operations. Next, we will describe the different writing methods of MySQL and SQL triggers in China, hoping to help you.

Trigger function:
When a record is inserted in a table in SQL or MySQL databases, a trigger is triggered to insert the same record to another table in the same database.
In the course of learning, we find that the two are written differently.
1. create two SQL tables SQL _test and SQL _tem. (The fields in the two tables are the same)

The code is as follows:
Create table SQL _test
(
Id int,
Name varchar (16)
)

Create table SQL _tem
(
Id int,
Name varchar (16)
)

The code is as follows:
/* SQL trigger writing */
Create trigger insert_ SQL _test on SQL _test
For insert
As
Insert into SQL _tem
Select * from inserted
Go
/* SQL trigger writing */

2. create two tables mysql_test and mysql_tem in MySQL. (The Fields of the two tables are the same. The table creation statement is similar to the preceding one)
The code is as follows:
/* MySQL trigger writing method */
Delimiter //
Create trigger insert_mysql_test before insert on test
For each row
Begin
Insert into tem set id = new id, name = new name;
/* Id after new. name is the field name of the test table */
End
//

The different writing methods of MySQL and SQL triggers are summarized for everyone. these experiences are summed up by careful people from their daily work. so, you also need to be careful at work to discover unexpected surprises.

BitsCN.com

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.