我需要将 sqlite 触发器转换为 mysql 触发器。我已经转换了以下 sqlite 触发器
create trigger arpinsert after insert on arp
begin
update arp set timeout = datetime('now', '60 seconds') where rowid = new.rowid and new.mac != '00:00:00:00:00:00';
update arp set timeout = datetime('now') where rowid = new.rowid and new.mac = '00:00:00:00:00:00';
end;
进入下面的mysql触发器
delimiter //
create
trigger arpBeforeInsert
before insert
on arp for each row
begin
if new.mac != '00:00:00:00:00:00' then
set new.timeout = date_add(now(), interval 60 second);
else
set new.timeout = now();
end if;
end;//
delimiter ;
我知道mysql触发器只触发受影响的行。 sqlite 触发器也是如此吗?如果我删除 where rowid = new.rowid
SQLite 触发器会更新整个表吗?
最佳答案
At this time SQLite supports only FOR EACH ROW triggers, not FOR EACH STATEMENT triggers. Hence explicitly specifying FOR EACH ROW is optional. FOR EACH ROW implies that the SQL statements specified in the trigger may be executed (depending on the WHEN clause) for each database row being inserted, updated or deleted by the statement causing the trigger to fire.
但是,这仅适用于触发器本身。 触发器内的任何 SQL 语句都是独立的(如果要访问其他表/行,则必须如此)。因此,执行不带 WHERE 子句的 UPDATE 将更新表的所有行,就像触发器外部一样。
关于mysql - sqlite 触发器对整个数据库起作用还是仅对更改的行起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31565979/