SQLite Forum

Statement that fires trigger is not executed when the trigger causes an error
Login
Hi,

I'm trying to understand what is the default behaviour of SQLite when there is an error in the BEGIN-END section of a trigger.

For example:

<pre>
  CREATE TABLE my_table (id INTEGER PRIMARY KEY);
  INSERT INTO my_table VALUES (1);

  CREATE TRIGGER R1
  AFTER DELETE ON my_table
  BEGIN
    DELETE FROM Non_existent_table WHERE id=OLD.id;
  END;
</pre>

So I created a table and then added a trigger that is doomed to fail.
If I try to remove something from `my_table` I get an error, of course:

<pre>
  DELETE FROM my_table WHERE id=1;
  Error: no such table: main.Non_existent_table
</pre>

Now, since I'm using AFTER DELETE on the trigger, I would expect that the original DELETE statement on `my_table` would have been executed, but that is not the case:
<pre>
  SELECT * FROM my_table;
  id        
  \----------
  1         
</pre>

Why is the original statement that caused the trigger to fire, not executed when there is an error on the trigger?  
Is it rolling back the changes by default?  
Or does SQLite parse the trigger's actions before executing anything? If so, why wasn't this parsing done when the trigger was created? Seems like that would make more sense.

Anyway, this may be a stupid question, but it's really bugging me that I can't figure it out.

Thanks