mysql - 如何仅在包含更改时才使用触发器在历史表中添加数据
问题描述
有一个 python 脚本可以更新 MySQL 表中的数据。问题是当没有对数据进行更改时,触发器会复制 history_table 中的每条记录。
create trigger organizations_history_update after update on organizations for each row
begin
declare N DATE;
set N = now();
UPDATE organizations_history
SET EndDate = N
WHERE id = OLD.id
AND EndDate IS NULL;
insert into organizations_history (id, name,current_version, db_maintenance_plan, custom_localization, custom_skin_for_ipad, custom_server_version, zendesk_id, StartDate, EndDate)
values (new.id, new.name, new.current_version, new.db_maintenance_plan, new.custom_localization, new.custom_skin_for_ipad, new.custom_server_version, new.zendesk_id, N, NULL);
end;
解决方案
推荐阅读
- json - kotlin.kotlin空指针异常
- javascript - 如何拆分 querySelectorAll 结果?
- python-3.x - 如何使用 Python 和 Beautiful Soup 修复 html 列表片段中缺少的 ul 标签
- vb.net - 我想在 ASP.NET Core 应用程序中使用 vbhtml 编辑器(只有编辑器而不是完整的剃须刀)
- android - GridLayout 仅显示第一列
- javascript - 如何从数组中删除所有数字?
- c++ - 如何从特定格式的字符串流中读取数字?
- python - 将变量值附加到 cv2.imwrite 函数
- javascript - Kendo UI Chart 禁用图例项右键单击事件
- linux - 如何记录每个命令的持续时间/结果并使用“历史”显示此信息?