更新时MySQL触发器无法正常工作

时间:2013-03-13 20:06:56

标签: mysql triggers

DELIMITER $$
USE `mydb`$$
DROP TRIGGER /*!50032 IF EXISTS */ `update`$$
CREATE
/*!50017 DEFINER = 'root'@'localhost' */
TRIGGER `update` AFTER UPDATE
ON `users`
FOR EACH ROW BEGIN
UPDATE `users2` SET `users2`.`username` = new.username AND `users2`.`password` = new.password WHERE `users2`.`id` = new.id;
END;
$$

它不会产生任何错误,也不会产生任何错误。

1 个答案:

答案 0 :(得分:1)

您的UPDATE声明不正确。

更改
UPDATE `users2` SET `users2`.`username` = new.username AND `users2`.`password` = new.password WHERE `users2`.`id` = new.id;
                                                       ^^^

UPDATE `users2`       
   SET `username` = new.username, `password` = new.password 
 WHERE `users2`.`id` = new.id;