Different Methods for writing MySQL and SQL triggers

Source: Internet
Author: User

<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.
<Trigger function>

1. Create two SQL tables SQL _test and SQL _tem. (The fields in the two tables are the same)

Copy codeThe Code is as follows: create table SQL _test
(
Id int,
Name varchar (16)
)

Create table SQL _tem
(
Id int,
Name varchar (16)
)Copy codeThe 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) Copy codeThe Code is as follows:/* Writing MySQL triggers */
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
//
/* MySQL trigger Writing Method */

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.