Do sqlite triggers trigger other triggers?(sqlite 触发器会触发其他触发器吗?)
问题描述
我正在尝试在 sqlite 中实现相当于ON UPDATE CURRENT_TIMESTAMP"MySQL 功能.我的想法是使用这样的触发器:
I am trying to implement the equivalent of the "ON UPDATE CURRENT_TIMESTAMP" MySQL feature in sqlite. My idea it to use a trigger like this:
CREATE TRIGGER last_update_trigger
AFTER UPDATE
ON mytable
FOR EACH ROW
BEGIN
UPDATE mytable SET last_update = CURRENT_TIMESTAMP WHERE id = old.id;
END
但这有一个问题.每次在该表的记录上发生更新时,触发器都会在同一记录上触发新的更新.这应该会一次又一次地触发触发器,从而导致无限循环的更新.
But there's a problem with this. Each time an update occurs on a record of this table, the trigger triggers a new update on this same record. This should trigger the trigger again, and again, leading to an infinite loop of updates.
这真的会发生吗?我的触发器中的更新会再次触发触发器吗?是否可以避免触发触发器内的触发器?
Is this really what will happen? Will the update in my trigger trigger the trigger again? Can I avoid triggering of triggers within triggers?
推荐答案
我们说的是 SQLite,对吧?
We're talking about SQLite, right?
最初,不专门支持递归触发器(上面怀疑的无限循环)来防止此问题.它们现在受支持,但默认情况下关闭.你可以,理论上,用
Originally, recursive triggers (the infinite loop suspected above) were not supported specifically to prevent this problem. They're now supported, but turned off by default. You can, in theory, turn them back on with
PRAGMA recursive_triggers = ON;
这篇关于sqlite 触发器会触发其他触发器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:sqlite 触发器会触发其他触发器吗?
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- SQL 临时表问题 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 更改自动增量起始编号? 2021-01-01