In sqlite3, is there a foreign_key integrity check?

I am just participating in sqlite, so I was surprised to see that my foreign_key restriction did not work when I was able to delete the parent record. After that, I found out that the pragma for foreign_key is disabled by default for each session. It seems strange there is no resource file (e.g. .exrc for vi, for example) that you can use to configure default pragmas for each session, but fine. So I have to recompile sqlite3 or just install it every time.

In any case, my question is that after I deleted the parent, is there a way to check the integrity of the mail against foreign key restrictions? That is, just tell sqlite to run the same logic as it does when it does it initially, if you included the pragma during insert or delete, etc.?

I see "pragma integrity_check", but it's just a search for corruption it seems.

Thanks Justin

+4
source share
2 answers

Starting with SQLite 3.7.16, PRAGMA foreign_key_check .

+5
source

Run the following command:

PRAGMA foreign_keys; 

The result will be:

 0 // foreign keys Disabled 1 // foreign keys Enabled 

To enable or disable foreign keys:

 PRAGMA foreign_keys = ON; 

or

 PRAGMA foreign_keys = OFF; 

Additional Information Here

0
source

Source: https://habr.com/ru/post/1479147/


All Articles