MYSQL trigger UPDATE triggers insert failure _mysql

Source: Internet
Author: User
Tags sql error

Today's work requires that you want to implement a history of the tables that will only update the status, so consider setting up triggers in the original table and writing the updated content to another table

So I tested it.

--Establish a test table create table ' Triggletest_triggle ' (
' id ' INT () not NULL,
' name ' VARCHAR (5) null DEFAULT NULL,
PRIMARY KEY (' id ')
)
collate= ' latin1_swedish_ci '
engine=innodb 
-Set the target table
create TABLE ' Triggletest ' (
' seq ' int (one) not NULL,
' id ' int (one) not null,
' name ' VARCHAR (5) null DEFAULT null,
PRI MARY KEY (' seq '),
INDEX ' id ' (' id ')
)
collate= ' latin1_swedish_ci '
engine=innodb; 
---write test data
INSERT into ' Triggletest_triggle ' VALUES (1, ' A '); 
--Create a trigger
DROP TRIGGER if EXISTS test1
create TRIGGER test1 after 
UPDATE on Triggletest_triggle
for Each ROW
BEGIN
inserts into triggletest (ID) values (new.id);

Execute the trigger statement, an error, the error content is as follows:

/* SQL error (1064): You have a error in your SQL syntax; Check the manual that corresponds to your MySQL server version for the right syntax to use near ' CREATE TRIGGER test1 
After UPDATE in triggletest_triggle for each
ROW
BEGIN ' in line 2 */
---The final implementation code
DROP TRIGGER if EXISTS tes T1;
CREATE TRIGGER test1 after UPDATE in test.triggletest_triggle for each ROW
BEGIN
INSERT into Triggletest (id,name) Values (new.id,new.name);

Analysis, due to the Access tool hedisql, resulting in the failure to create a trigger, the same statement, executed in the Hedisql, error, use shell invoke MySQL, direct execution program, success.

Related Article

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.