Small. Fast. Reliable.
Choose any three.
*** 31,41 ****
             CONSTRAINT fk_foo_id REFERENCES foo(id) ON DELETE CASCADE
    );
  
! Table bar has a foreign key reference to the primary key column in the _foo_ table. Although SQLite supports this syntax (as well as named foreign key constraints), it ignores 
  them. So if you want the references enforced, you need to create triggers to do the job.
  
  Triggers were added to SQLite version 2.5, so most users can take advantage of this feature. Each 
! constraint must have three triggers: one for INSERTs, one for UPDATESs, and one for DELETESs. The INSERT trigger looks like this:
  
    CREATE TRIGGER fki_bar_foo_id
    BEFORE INSERT ON bar
--- 31,43 ----
             CONSTRAINT fk_foo_id REFERENCES foo(id) ON DELETE CASCADE
    );
  
! Table bar has a foreign key reference to the primary key column in the _foo_ table. Although SQLite
! supports this syntax (as well as named foreign key constraints), it ignores
  them. So if you want the references enforced, you need to create triggers to do the job.
  
  Triggers were added to SQLite version 2.5, so most users can take advantage of this feature. Each
! constraint must have three triggers: one for INSERTs, one for UPDATESs, and one for DELETESs. The
! INSERT trigger looks like this:
  
    CREATE TRIGGER fki_bar_foo_id
    BEFORE INSERT ON bar
***************
*** 45,51 ****
    END;
  
  If your foreign key column is not NOT NULL, the trigger's
! WHERE clause needs to an extra expression:
  
    CREATE TRIGGER fki_bar_foo_id
    BEFORE INSERT ON bar
--- 47,53 ----
    END;
  
  If your foreign key column is not NOT NULL, the trigger's
! WHERE clause needs an extra expression:
  
    CREATE TRIGGER fki_bar_foo_id
    BEFORE INSERT ON bar
***************
*** 77,83 ****
  
  The DELETE trigger is, of course, the reverse of the INSERT and 
  UPDATE triggers, in that it applies to the primary key table, rather than the foreign key 
! table. To whit, in our example, it watches for DELETEs on the foo 
  table:
  
    CREATE TRIGGER fkd_bar_foo_id
--- 79,85 ----
  
  The DELETE trigger is, of course, the reverse of the INSERT and
  UPDATE triggers, in that it applies to the primary key table, rather than the foreign key
! table. To wit, in our example, it watches for DELETEs on the foo
  table:
  
    CREATE TRIGGER fkd_bar_foo_id
***************
*** 92,98 ****
  in databases with referential integrity enforcement, sometimes specified explicitly as ON 
  DELETE RESTRICT. But sometimes you want the deletes in the primary key table to 
  _cascade_ to the foreign key tables. Such is what our example declaration above specifies, and 
! this is the trigger to to the job:
  
  
    CREATE TRIGGER fkd_bar_foo_id
--- 94,100 ----
  in databases with referential integrity enforcement, sometimes specified explicitly as ON
  DELETE RESTRICT. But sometimes you want the deletes in the primary key table to
  _cascade_ to the foreign key tables. Such is what our example declaration above specifies, and
! this is the trigger to do the job:
  
  
    CREATE TRIGGER fkd_bar_foo_id