Skip to content

Instantly share code, notes, and snippets.

@SergKolo
Created October 27, 2018 22:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SergKolo/2d7230c3718f62dfb2fe2931bdffafda to your computer and use it in GitHub Desktop.
Save SergKolo/2d7230c3718f62dfb2fe2931bdffafda to your computer and use it in GitHub Desktop.
conditional trigger in sqlite
DROP TABLE IF EXISTS tb1;
DROP TABLE IF EXISTS tb2;
DROP TABLE IF EXISTS ch;
CREATE TABLE tb1 (a INT, b TEXT);
INSERT INTO tb1 VALUES (1,'foo'),(2,'bar');
CREATE TABLE tb2 AS SELECT * FROM tb1;
CREATE TABLE ch (choice TEXT);
CREATE TRIGGER conditional_1 AFTER INSERT ON ch
WHEN new.choice = 'tb1'
BEGIN
INSERT INTO tb1 VALUES (3,'THIS IS conditional_1 test');
END;
CREATE TRIGGER conditional_2 AFTER INSERT ON ch
WHEN new.choice = 'tb2'
BEGIN
INSERT INTO tb2 VALUES (3,'THIS IS conditional_2 test');
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment