On Wed, Dec 12, 2012 at 2:29 PM, Levi Haskell (BLOOMBERG/ 731 LEXIN) <
lhask...@bloomberg.net> wrote:

> My suggestion would be to have check_integrity command verify referential
> integrity as well only if it's executed while the foreign key enforcement
> is enabled on the connection.
>

The latest SQLite from trunk (not the 3.7.15.1 patch release, but the code
that is destined to become 3.7.16) has a new pragma:

    PRAGMA foreign_key_check;
    PRAGMA foreign_key_check(TABLE);

The second from checks all of the REFERENCES clauses in TABLE.  The first
form checks the keys on all tables in the database.

The result of the pragma is a table, with one row per mismatched key.  The
row contains the name of the child table, the rowid of the child table, the
name of the parent table, and the "foreign key index" which is an integer
that describes the foreign key in PRAGMA foreign_key_list(CHILD).  If the
foreign_key_check pragma returns an empty set, that means that all of the
keys are correct.

PRAGMA foreign_key_check works regardless of whether or not foreign keys
are currently enabled or disabled.


-- 
D. Richard Hipp
d...@sqlite.org
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to