Created
October 27, 2018 22:26
-
-
Save SergKolo/2d7230c3718f62dfb2fe2931bdffafda to your computer and use it in GitHub Desktop.
conditional trigger in sqlite
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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