Ajoutez ce déclencheur à votre ExpenseTable
CREATE TRIGGER ExpenseSum AFTER INSERT ON ExpenseTable FOR EACH ROW
BEGIN
UPDATE ProjectsTable P
SET ExpenseTotal =
(SELECT SUM(ExpenseAmount) from ExpenseTable
where ExpenseTable.ProjectID= P.ProjectID)
where P.ProjectID = New.ProjectID;
END
N'oubliez pas d'ajouter le déclencheur After Update
et After Delete
pour mettre à jour ExpenseTotal