Leaves what's there alone and just starts enforcing from when you turn it on. 
It'll only go actively looking for issues if you do a pragma foreign_key_check;

sqlite> pragma foreign_keys = off;

sqlite> create table parent (id integer primary key);

sqlite> create table child (id integer primary key, parentID int references 
parent);

sqlite> insert into parent values (1), (2);

sqlite> insert into child (parentID) values (1), (2), (3), (4);

sqlite> pragma foreign_key_check;
table|rowid|parent|fkid
child|3|parent|0
child|4|parent|0

sqlite> pragma foreign_keys = on;

sqlite> insert into parent values (3);

sqlite> update child set parentID = parentID + 1;
Error: FOREIGN KEY constraint failed

sqlite> pragma foreign_key_check;
table|rowid|parent|fkid
child|4|parent|0


-----Original Message-----
From: sqlite-users [mailto:sqlite-users-boun...@mailinglists.sqlite.org] On 
Behalf Of x
Sent: Tuesday, November 28, 2017 10:27 AM
To: sqlite-users@mailinglists.sqlite.org
Subject: [sqlite] Foreign key help

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?

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

Reply via email to