Thanks, this is great - I'll read up on expression syntax and usage.
On Fri, Oct 1, 2010 at 3:11 PM, Drake Wilson <dr...@begriffli.ch> wrote: > Quoth Jim Mellander <jmellan...@lbl.gov>, on 2010-10-01 14:38:03 -0700: >> Hi: >> >> I want to use to trigger on deletion of a detail record to >> automatically delete a summary record, if not more detail records >> exist, something like: >> >> CREATE TRIGGER detail_delete AFTER DELETE ON detail >> BEGIN >> -- here I don't know syntax >> IF COUNT(detail records with key) = 0 DELETE summary WHERE >> key=old.key; >> END; > > SQLite triggers don't use an imperative language with full control > structures, just basic SQL. However, in this case you can use a WHEN > clause: > > CREATE TRIGGER auto_delete_summary AFTER DELETE ON detail > FOR EACH ROW WHEN NOT EXISTS (SELECT * FROM detail WHERE key = OLD.key) > BEGIN > DELETE FROM summary WHERE key = OLD.key; > END; > > ---> Drake Wilson > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users