SQLite命令
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
一些有用的 SQLite 命令
显示表结构:
sqlite> .schema [table]
获取所有表和视图:
sqlite > .tables
获取指定表的索引列表:
sqlite > .indices [table ]
导出数据库到 SQL 文件:
sqlite > .output [filename ]
sqlite > .dump
sqlite > .output stdout
从 SQL 文件导入数据库:
sqlite > .read [filename ]
格式化输出数据到 CSV 格式:
sqlite >.output [filename.csv ] sqlite >.separator ,
sqlite >select* from test;
sqlite >.output stdout
从 CSV 文件导入数据到表中:
sqlite >create table newtable (id integer primary key, value text ); sqlite >.import [filename.csv ] newtable
备份数据库:
/* usage: sqlite3
[database] .dump > [filename] */ sqlite3 mytable.db .dump > backup.sql
恢复数据库:
/* usage: sqlite3
[database ]<[filename ]*/
sqlite3 mytable.db < backup.sql 设置格式化查询结果:
1 sqlite> .mode column;
2 sqlite> .header on;
3 sqlite> select * from test;
4 id value
5 ----------- -------------
6 1 Micheal
7 2 Jenny
8 3 Francis
9 4 Kerk
.mode column 将设置为列显示模式,.header 将显示列名。