简体   繁体   English

有关SQL触发器的问题

[英]Question about SQL triggers

Say there are two relations r and s such that the foreign key B of r references the primary key A of s. 假设存在两个关系r和s,使得r的外键B引用s的主键A。 How can the trigger mechanism be used to implement the on delete cascade option, when a tuple is deleted from s. 从s中删除元组时,如何使用触发机制来实现on delete级联选项。

In SQLite syntax: 在SQLite语法中:

CREATE TRIGGER
  AFTER DELETE ON s
  FOR EACH ROW
BEGIN
  DELETE FROM r WHERE r.B = old.A;
END;

This creates a trigger that run on each row deleted from s. 这将创建一个触发器,该触发器将在从s删除的每一行上运行。 The trigger deletes the corresponding records from r, given the foreign key relationship you indicated. 给定您指定的外键关系,触发器将从r中删除相应的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM