终端使用sqlite记录
2018-02-28 本文已影响31人
loongod
创建或打开数据库
sqlite3 user.db

退出
.quit

查看创建数据库的SQL命令
.schema

创建数据表
create table tableName(firstField,secondField,thirdField);

插入数据
insert into tableName(firstField,secondField,thirdField) values(1,"second","3");
insert into tableName(firstField,secondField,thirdField) values(12,"second2","32");
注意:不要忘了分号

如果忘了句尾的分号,就会变成换行了,效果如下:

看下插入的数据:

修改数据
update tableName set secondField="loongod" where firstField=1;

查询数据表
简单的查询:
select * from tableName;
默认的模式是 list

根据条件查询
select * from users where name="loongod" and password="111";

设置显示模式为列模式:
.mode column

设置显示模式为插入语句:
.mode insert

设置显示模式为行:
.mode line

设置分隔符:
.separator "#"

在头部显示字段名:
.heaer on
设置off
为关闭

查询数据库信息
.databases

查询数据库中表的信息
.tables

显示当前显示格式的配置
.show

显示数据库的SQL脚本(后面添加表名则为形成表的SQL脚本)
.dump


导出SQL文件
sqlite3 user.db .dump > initUserDB.sql


导入SQL文件
sqlite3 user.db .dump < initUserDB.sql
删除
删除表中的所有记录
delete from tableName;

按条件删除表中数据
delete from users where id = 1;

删除表
drop table tableName;
