如何转储某些 SQLite3 表的数据? [英] How do I dump the data of some SQLite3 tables?

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

问题描述

如何转储数据库的某些 SQLite3 表(不是所有表)的数据,并且仅转储数据,而不转储模式?转储应该是 SQL 格式,因为它应该很容易在以后重新输入到数据库中,并且应该从命令行完成.类似的东西

How do I dump the data, and only the data, not the schema, of some SQLite3 tables of a database (not all the tables)? The dump should be in SQL format, as it should be easily re-entered into the database later and should be done from the command line. Something like

sqlite3 db .dump

但不会转储架构并选择要转储的表.

but without dumping the schema and selecting which tables to dump.

推荐答案

你没有说你想用转储的文件做什么.

You're not saying what you wish to do with the dumped file.

我会使用以下内容来获取一个 CSV 文件,我可以将其导入到几乎所有内容中

I would use the following to get a CSV file, which I can import into almost everything

.mode csv 
-- use '.separator SOME_STRING' for something other than a comma.
.headers on 
.out file.csv 
select * from MyTable;

如果您想重新插入不同的 SQLite 数据库,则:

If you want to reinsert into a different SQLite database then:

.mode insert <target_table_name>
.out file.sql 
select * from MyTable;

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

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