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.