且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Sqlite:如何重置所有数据库表?

更新时间:2023-02-10 13:56:53

由于数据库只是一个文件,您确实可以删除它.如果您想要更自动化的操作,您可以使用以下代码以编程方式完成所有操作:

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. 恢复您的架构:

  1. Recover your schema:

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

断开与数据库的连接

删除数据库文件

使用上述查询返回的内容再次创建您的架构

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

如果您对原始数据库使用了任何特定选项(page_size 等),它们也必须手动声明.

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