Sqlite: How do I reset all database tables?

让人想犯罪 __ 提交于 2019-12-22 04:35:10

问题


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.


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/3600075/sqlite-how-do-i-reset-all-database-tables

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!