On 2 Feb 2017, at 2:38pm, Michael Tiernan <michael.tier...@gmail.com> wrote:

> So that makes sense (I think) and isn't causing a problem for me but then, a 
> little further on it says:
> 
>   If a WHEN clause is supplied, the SQL statements specified are only
>   executed for rows for which the WHEN clause is true. If no WHEN
>   clause is supplied, the SQL statements are executed for all rows.
> 
> My quandary comes from the last part of that statement "executed for all 
> rows". Does that mean "for all rows in the table" or does it mean "for all 
> rows /modified/ in the table" or "all rows previously mentioned as being 
> inserted, updated, or deleted by the statement causing the trigger to fire"?

(Slight handwaving, because this probably isn’t the way things work internally.)

The check is done for each row modified.
The trigger is triggered each time the WHERE clause is satisfied.
When a trigger is triggered it is applied to one row of the table.

Each time you modify any row of any table, SQLite checks the 'WHERE' clause  
each TRIGGER on that table to see whether it needs to bring that TRIGGER into 
play.  If that modification of that row doesn’t satisfy the WHERE clause, 
nothing else about the TRIGGER is processed.  If that modification does satisfy 
the WHERE clause then the trigger is performed on that modification.

If you issued an UPDATE command which modified six rows of the table, you 
should imagine the check being done six times, but the trigger would be 
performed any number from 0 to 6 times.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@mailinglists.sqlite.org
http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to