[prev in list] [next in list] [prev in thread] [next in thread] 

List:       sqlite-users
Subject:    Re: [sqlite] Foreign Key constraint checking
From:       Simon Slavin <slavins () hearsay ! demon ! co ! uk>
Date:       2009-07-31 20:31:08
Message-ID: 30C79597-081A-44E2-8D33-88440A76F113 () hearsay ! demon ! co ! uk
[Download RAW message or body]


On 31 Jul 2009, at 8:25pm, Shaun Seckman (Firaxis) wrote:

> I am well aware that SQLite doesn't enforce FK's and that a way around
> this is to use triggers.  This lack of enforcing actually has worked  
> to
> my advantage as when populating my database I can insert data out of
> order.  However, after all data has been inserted into the database,  
> I'd
> like to perform some constraint checking to ensure that any FK column
> value correctly matches a row that the FK references.  Is there any
> built-in methods or code snippits I can use for this or will I just  
> have
> to roll my own?

Dump the database with the command-line tool.  Take a look at the file  
it produces and move all the INSERT commands to the end.  Then use the  
'.read.' command to create a new database with these commands.  Then  
check to see you have the same number of records in all tables.

Not easy to automate, but it's good for a one-off check after a  
monster import job.

Simon.
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic