Trigger in sqlite different database

sqlite, triggers

Solution

This is not possible.

- In SQLite, DML inside triggers can only modify tables of the same database (see here). You cannot modify tables of an attached database.

- Similarly, you cannot declare triggers for an attached database (to do it the other way) unless you declare them TEMPORARY.

Hence, (only) the following is possible:

For A.sqlite:

create table T1(id integer primary key);

For B.sqlite:

create table T2(id integer primary key);
attach 'A.sqlite' as A;
create temporary trigger T1_del after delete on A.T1 
begin
    delete from T2 where id = OLD.id;
end;

But that would only propagate deletes from T1 to T2 within the connection that declared the temporary trigger. If you opened A.sqlite separately, the trigger would not be there.

Problem

I have 2 different database 'A' and 'B'.I need to create a trigger that when I would insert any entry in table 'T1' of database 'A' then entries of table 'T2' of database 'B' would gets deleted. Kindly suggest me a way!!

Original source