更新触发器导致目标表的列设置为零

时间:2018-11-14 08:56:48

标签: mysql

更新触发器导致目标表的列设置为零 这是代码

CREATE TRIGGER `inventory-company-update-trigger` AFTER UPDATE ON `db_company`
 FOR EACH ROW BEGIN
    UPDATE inventory_companies 
    SET name = NEW.dc_name 
    AND updated_at = NOW() 
    WHERE name = OLD.dc_name;
END

1 个答案:

答案 0 :(得分:1)

您正在使用SET name = NEW.dc_name AND updated_at = NOW()

对代码NEW.dc_name AND updated_at = NOW()进行评估,如果失败,则结果为0

您可能只是想更新两列nameupdated_at,例如:

UPDATE inventory_companies 
SET name = NEW.dc_name 
  , updated_at = NOW() 
 WHERE name = OLD.dc_name;