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

本文标题为:sqlite 触发器会触发其他触发器吗?

基础教程推荐