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 触发器会触发其他触发器吗?
基础教程推荐
- 在 VB.NET 中更新 SQL Server DateTime 列 2021-01-01
- 如何在 SQL Server 的嵌套过程中处理事务? 2021-01-01
- Sql Server 字符串到日期的转换 2021-01-01
- 使用pyodbc“不安全"的Python多处理和数据库访问? 2022-01-01
- SQL Server:只有 GROUP BY 中的最后一个条目 2021-01-01
- ERROR 2006 (HY000): MySQL 服务器已经消失 2021-01-01
- 无法在 ubuntu 中启动 mysql 服务器 2021-01-01
- SQL Server 2016更改对象所有者 2022-01-01
- 将数据从 MS SQL 迁移到 PostgreSQL? 2022-01-01
- SQL Server 中单行 MERGE/upsert 的语法 2021-01-01