Foreign key support

Foreign keys are an important feature in modern database design, to enforce database integrity:
CREATE TABLE orders (
   ... ,
   FOREIGN KEY(ord_customer) REFERENCES customer(cust_num) )
  )

SQLite (3.6.19 and +) implements foreign key support, but this feature is not enabled by default. In fact, it is possible to define foreign keys on tables, but when doing database operations, the constraints are not enforced until you enable it explicitly with a PRAGMA command.

Solution

In order to turn on foreign key constraint checking, you must issue a PRAGMA command, which can for example be executed with a EXECUTE IMMEDIATE instruction:
EXECUTE IMMEDIATE "PRAGMA foreign_keys = ON"

Future releases of SQLite might change this, so that foreign key constraints enabled by default.