lundi 6 juillet 2015

Updating table X on an Insert in table Y, with an SQLite trigger

Elaboration: When an INSERT happens in Table X, the count_updater trigger should update a column in Table Y where the _did in both tables match. This should happen only for the freshly inserted row in Table X.

Pseudo-structures

Table X
 _id integer primarykey
 _did integer...
 ...
Table Y
 _did integer primarykey
 X_Count integer ...
...

The trigger script:

CREATE TRIGGER count_updater AFTER INSERT ON X 
BEGIN 
    UPDATE Y SET X_Count = X_Count + 1 WHERE _did = NEW._did; 
END;

The trigger above fails. Kindly point out the mistake or help with the script as it should be. Many thanks in advance!

Aucun commentaire:

Enregistrer un commentaire