SQLite Forum

Reset database
> Is there an SQL i.e. a programmatic way to reset a database to the same state as it was when it was created?

So many contradictions in one sentence, but since we're nice people, let's try answer them all after dissection:

- Is there a Programmatic way? - Yes
- Is there a SQL way? - No
- when it was created? (read: before) - Yes (Unlink the file, reopen in SQLite)
- when it was created? (read: after the FILE was created but nothing in the DB yet) - Yes, same as previous point.
- when it was cretaed? (read: after, with content) - No, you have to truncate each table, or drop and recreate it, then redo whatever data entry was part of the create process, and even then you will have a different schema version etc. The only way to do this programmatically is painstakingly manual, in *any* Database engine).

> I am pre-empting failure when I have just read access to the database

How can you change the "state" of anything in the DB, never mind the DB itself, to anything else (historic or otherwise) when you only have read-only access to it?   
Further to that, what good is resetting an empty DB if you only have read-only access to it? It contains no information that would be useful to you and you certainly cannot add any. 

I'm going to just assume you were intoxicated when posting and that you do have some write access to the file/directory.

If it's some standard setup DB, you could just keep a copy of the file around by another name, then once all connections to it are closed, replace it with the pre-made file and reopen. Be sure those connections are closed though, else everything will explode and everyone will die.