Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite Trigger Expression For Deleting Rows

I've 2 tables A(id, Name), B(id, fid, Name) where A.id = B.fid, My requirement is I want to delete Row in B whenever row in A deletes

Here is query which i tried but it gives me Error near B..

Create Trigger Delete_B_trigger After Delete on A For each row Begin Delete from B where fid = id; End
like image 744
Pradeep Avatar asked Mar 04 '13 08:03

Pradeep


1 Answers

The DELETE command requires a FROM.

To access values in the triggering table, you have to use the OLD or NEW aliases.

CREATE TRIGGER Delete_B_trigger
AFTER DELETE ON A
FOR EACH ROW
BEGIN
    DELETE FROM B WHERE fid = OLD.id;
END
like image 175
CL. Avatar answered Sep 28 '22 06:09

CL.