首先在当前目录下创建数据库,代码如下:
[ouyangxi@DESKTOP-QNJ4U2U code]$ sqlite3 tax.db SQLite version 3.22.0 2018-01-22 18:45:57 Enter ".help" for usage hints. sqlite>
接着在数据库中创建表:
sqlite> create table tax( ...> id integer PRIMARY KEY AUTOINCREMENT, //序号的自增 ...> startTime timestamp, //创建时间 ...> money varchar(20), ...> unite varchar(20) ...> );
在数据库中可以创建多个表:
sqlite> create table tax1( ...> id integer PRIMARY KEY AUTOINCREMENT, ...> startTime timestamp, ...> money varchar(20), ...> unite varchar(20) ...> );
使用如下代码显示表的个数:
sqlite> .tables tax tax1
同时也可删除多余的表:
sqlite> drop table tax1; sqlite> .tables tax
接下来进行初始化赋值:
sqlite> insert into tax(startTime,money,unite) values (current_timestamp,'20','元'); sqlite> insert into tax(startTime,money,unite) values (current_timestamp,'30','元'); sqlite> insert into tax(startTime,money,unite) values (current_timestamp,'40','元');
而后可以进行查询
sqlite> select * from tax;//全部查询 sqlite> select * from tax where money='20';//条件查询 sqlite> select id, datetime(startTime),money,unite from tax;//日期查询
完成SQlite3数据库的建立