Thanks David / Simon.

From: sqlite-users <> on behalf of 
Simon Slavin <>
Sent: Tuesday, November 28, 2017 3:36:51 PM
To: SQLite mailing list
Subject: Re: [sqlite] Foreign key help

On 28 Nov 2017, at 3:26pm, x <> wrote:

> If I have foreign keys in place but always have foreign_keys = OFF then one 
> day start SQLite with foreign_keys = ON what happens? Does SQLite suddenly 
> check all foreign keys and report / delete violations or does it leave 
> everything as is and just enforce foreign keys from that point on?

No.  There is no automatic check.  If you have broken a foreign key constraint 
while "foreign_keys = OFF" it may only be discovered some time in the future, 
or it may live on for as long as the database is used.

However, you can force SQLite to check all foreign keys any time you want using


        PRAGMA foreign_key_check

If it returns no rows, then there are no problems.  This check will work even 
while "foreign_keys = OFF", so you can check it before you turn that PRAGMA 
back on.

sqlite-users mailing list
sqlite-users mailing list

Reply via email to