In SQLITE and a banking transactions table with columns cargo, abono, saldo. How do I make sure that the next INSERT at the end of the table has the NEW.balance = balance + NEW. debit - NEW.credit
I have tried:
CREATE TRIGGER ChecarSaldo
BEFORE INSERT ON BANORTE
BEGIN
SELECT RAISE(FAIL, 'NO ES EL SIGUIENTE MOVIMIENTO') FROM BANORTE WHEN
Saldo = (SELECT Saldo FROM BANORTE ORDER BY fecha DESC LIMIT 1) + NEW.cargo - NEW.abono)
END;
It says syntax error at the equal sign.