Sqlite:如何重置所有数据库表? [英] Sqlite: How do I reset all database tables?

查看:42
本文介绍了Sqlite:如何重置所有数据库表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要一个调试函数来执行此操作,但我不知道是否已经存在.为我的每张桌子检查并使用drop table"会很痛苦.

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.

感谢帮助.

推荐答案

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

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.

这篇关于Sqlite:如何重置所有数据库表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆