PRAGMA foreign_key_check
The foreign_key_check pragma checks the database, or the table called "table-name", for foreign key constraints that are violated.
PRAGMA schema.foreign_key_check; PRAGMA schema.foreign_key_check(table-name);
On the sample database
What PRAGMA foreign_key_check returns on the sample database, in SQLite 3.54.1 as built for the browser by sql.js (the first 12 of 14 rows):
| table | rowid | parent | fkid |
|---|---|---|---|
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
| playlist_tracks | NULL | tracks | 0 |
What the SQLite documentation says
The foreign_key_check pragma checks the database, or the table called "table-name", for foreign key constraints that are violated. The foreign_key_check pragma returns one row output for each foreign key violation. There are four columns in each result row. The first column is the name of the table that contains the REFERENCES clause. The second column is the rowid of the row that contains the invalid REFERENCES clause, or NULL if the child table is a WITHOUT ROWID table. The third column is the name of the table that is referred to. The fourth column is the index of the specific foreign key constraint that failed. The fourth column in the output of the foreign_key_check pragma is the same integer as the first column in the output of the foreign_key_list pragma. When a "table-name" is specified, the only foreign key constraints checked are those created by REFERENCES clauses in the CREATE TABLE statement for table-name.
From sqlite.org's pragma documentation for SQLite 3.54.1, in the public domain.
← encoding · foreign_key_list →