使用以下触发器更新mysql 5.0.7中另一个数据库中的用户表 触发器的创建不会产生错误,但是在更新第一个数据库中的用户表时,触发器不起作用。有什么建议吗?
DELIMITER $$
DROP TRIGGER IF EXISTS after_update_user;
CREATE TRIGGER after_update_user;
AFTER UPDATE ON db_test.user FOR EACH ROW;
BEGIN
UPDATE TABLE db_testplus.user;
SET name = NEW.name;
WHERE id = NEW.id;
END
$$
DELIMITER ;
我也使用了这个没有分号但仍然相同的代码
DELIMITER $$
DROP TRIGGER IF EXISTS after_update_user
CREATE TRIGGER after_update_user
AFTER UPDATE ON db_test.user FOR EACH ROW
BEGIN
UPDATE TABLE db_testplus.user
SET name = NEW.name
WHERE id = NEW.id
END;
$$
DELIMITER ;
最后有效的代码
delimiter |
DROP TRIGGER IF EXISTS after_update_user|
CREATE TRIGGER after_update_user AFTER UPDATE ON db_test.user
FOR EACH ROW BEGIN
UPDATE db_testplus.user SET name = NEW.name WHERE id = NEW.id;
END;
|
delimiter ;
答案 0 :(得分:2)
请您查看下面的
AFTER UPDATE ON db_test.user FOR EACH ROW
BEGIN
UPDATE TABLE db_testplus.user
SET name = NEW.name
WHERE id = NEW.id
END;
答案 1 :(得分:0)
这在MySQL 5.1.73中对我有效:
CREATE TRIGGER `after_update`
AFTER UPDATE ON `test_table`
FOR EACH ROW UPDATE another_db.updated_table
SET some_name = NEW.some_name
WHERE id = NEW.id