接下来往表里中写入一些数据:
sqlite> insert into mytable(id, value) values(1, 'Micheal'); sqlite> insert into mytable(id, value) values(2, 'Jenny'); sqlite> insert into mytable(value) values('Francis'); sqlite> insert into mytable(value) values('Kerk');查询数据:
sqlite> select * from mytable; 1|Micheal 2|Jenny 3|Francis 4|Kerk设置格式化查询结果:
sqlite> .mode column; sqlite> .header on; sqlite> select * from mytable; id value ----------- ------------- 1 Micheal 2 Jenny 3 Francis 4 Kerk.mode column 将设置为列显示模式,.header 将显示列名。
修改表结构,增加列:
sqlite> alter table mytable add column email text not null '' collate nocase;;创建视图:
sqlite> create view nameview as select * from mytable;创建索引:
sqlite> create index test_idx on mytable(value);
4. 一些有用的 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
标签:SQLite
相关阅读 >>
Sqlite数据库的介绍与java操作Sqlite的实例讲解
android实现搜索功能并将搜索结果保存到Sqlite中(实例代码)
navicat premium操作mysql数据库(执行sql语句)
更多相关阅读请进入《Sqlite》频道 >>

数据库系统概念 第6版
本书主要讲述了数据模型、基于对象的数据库和XML、数据存储和查询、事务管理、体系结构等方面的内容。