>> SELECT RAISE(FAIL,'album has songs cannot be deleted')
>> WHERE (SELECT count(album_fk) FROM songs WHERE (album_fk = OLD.id) > 0);
> 
> Or simply
> 
> where old.id in (select album_fk from songs)

Or most efficiently:

where exists (select 1 from songs where old.id = album_fk)

If the columns are indexed, the advantage is negligible, but it's good SQL 
practice to avoid "count" and "in" when you only care if there is any existence 
of a match. As far as I'm aware, "count" and "in" do a full table scan, whereas 
"exists" only scans up to the first match.

Tom
BareFeetWare
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to