Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlite: How do I reset all database tables?

Tags:

sqlite

reset

I want a debug function to do this, but I'm unaware of whether one already exists. Going through and using 'drop table' for each of my tables will be a pain.

Help appreciated.

like image 970
Hamster Avatar asked Aug 30 '10 11:08

Hamster


2 Answers

Since the database is just one file, you can indeed just erase it. If you want something more automatic, you can use the following to do it all programmatically:

  1. Recover your schema:

    SELECT group_concat(sql,';') FROM sqlite_master;

  2. Disconnect from the database

  3. Delete the database file

  4. Create your schema again with what was returned from the above query

If you used any particular options for your original database (page_size, etc), they will have to be declared manually as well.

like image 180
MPelletier Avatar answered Oct 14 '22 21:10

MPelletier


to "drop database" for sqlite, simply delete the database file (and recreate if needed)

like image 40
second Avatar answered Oct 14 '22 22:10

second