开发者

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. How can the trigger mechanism be used to implement the on delete cascade option, when a tuple is deleted from s.


In SQLite syntax:

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. The trigger deletes the corresponding records from r, given the foreign key relationship you indicated.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜