Skip to content

Instantly share code, notes, and snippets.

@ddmitov
Created August 5, 2014 09:43
Show Gist options
  • Save ddmitov/dc19a325ea578ff8f9a7 to your computer and use it in GitHub Desktop.
Save ddmitov/dc19a325ea578ff8f9a7 to your computer and use it in GitHub Desktop.
Example SQLite triggers
CREATE TRIGGER calculate_vat_new AFTER INSERT ON inventory
BEGIN
UPDATE inventory SET PRICE_VAT = new.PRICE/100*20+new.PRICE WHERE id = new.id;
END;
CREATE TRIGGER calculate_vat UPDATE OF PRICE ON inventory
BEGIN
UPDATE inventory SET PRICE_VAT = new.PRICE/100*20+new.PRICE WHERE id = old.id;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment