sqlite 触发器会触发其他触发器吗?

Do sqlite triggers trigger other triggers?(sqlite 触发器会触发其他触发器吗?)
本文介绍了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 触发器会触发其他触发器吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

FastAPI + Tortoise ORM + FastAPI Users (Python) - Relationship - Many To Many(FastAPI+Tortoise ORM+FastAPI用户(Python)-关系-多对多)
Window functions not working in pd.read_sql; Its shows error(窗口函数在pd.read_sql中不起作用;它显示错误)
(Closed) Leaflet.js: How I can Do Editing Geometry On Specific Object I Select Only?((已关闭)Leaflet.js:如何仅在我选择的特定对象上编辑几何图形?)
in sqlite update trigger with multiple if/Case Conditions(在具有多个IF/CASE条件的SQLite UPDATE触发器中)
Android: Why is Room so slow?(Android:为什么Room这么慢?)
Remote Procedure call failed with sql server 2008 R2(使用 sql server 2008 R2 的远程过程调用失败)