Usage of mysql trigger update instead of new

Source: Internet
Author: User

The mysql trigger cannot directly use update to update data. This is not a mysql bug, but the official saying that using update may lead to an endless loop, we recommend that you directly use the new value variable.

In mysql, the insert and update triggers cannot be used for the update and insert operations. The official instructions are to prevent endless loops. The solution is to directly assign values to fields in new, in fact, it is quite convenient, but it also shows that the mysql technology needs to be enhanced. After all, the functions that mssql can implement will cause problems to you.

The Code is as follows: Copy code

DELIMITER $

USE 'zn _ home' $

Drop trigger /*! 50032 if exists */'add _ name' $

CREATE

/*! 50017 DEFINER = 'test' @ '% '*/

TRIGGER 'add _ name' before insert on 'uchome _ sow'

FOR EACH ROW BEGIN

DECLARE _ name CHAR (20 );

SELECT 'name' INTO _ name FROM uchome_space WHERE uid = new. uid;

SET new. name = _ name;

END;

$

We only need to use SET new. name = _ name; to replace update.

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.