首先在當前目錄下建立數據庫,代碼以下:html
[ouyangxi@DESKTOP-QNJ4U2U code]$ sqlite3 tax.db SQLite version 3.22.0 2018-01-22 18:45:57 Enter ".help" for usage hints. sqlite>
接着在數據庫中建立表:git
sqlite> create table tax( ...> id integer PRIMARY KEY AUTOINCREMENT, //序號的自增 ...> startTime timestamp, //建立時間 ...> money varchar(20), ...> unite varchar(20) ...> ); //自定義money和unite,可是在後面賦值的時候需保持名稱相同
在數據庫中能夠建立多個表:sql
sqlite> create table tax1( ...> id integer PRIMARY KEY AUTOINCREMENT, ...> startTime timestamp, ...> money varchar(20), ...> unite varchar(20) ...> );
使用以下代碼顯示錶的個數:數據庫
sqlite> .tables
tax tax1 //顯示結果
同時也可刪除多餘的表:spa
sqlite> drop table tax1;
sqlite> .tables
tax
接下來進行初始化賦值:code
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','元'); //注意tax括號裏的變量順序應與建立該表時的變量順序一致
#查詢sqlite
能夠進行所有查詢:htm
sqlite> select * from tax; 1|2020-04-24 11:58:29|20|元 2|2020-04-24 11:58:50|30|元 3|2020-04-24 11:58:57|40|元
也能夠經過條件,選擇查詢:blog
sqlite> select * from tax where money='20'; 1|2020-04-24 11:58:29|20|元 //這裏選擇money變量進行選擇查詢
還能夠經過日期,進行查詢:it
sqlite> select id, datetime(startTime),money,unite from tax; 1|2020-04-24 11:58:29|20|元 2|2020-04-24 11:58:50|30|元 3|2020-04-24 11:58:57|40|元
//能夠經過他來統計當天的收入
至此,以完成了sqlite3數據庫的創建,表的建立,表的初始化賦值,查詢表中數據,按條件查找等功能。
另詳細功能,見網址:https://www.cnblogs.com/zengjfgit/p/4622208.html
正是步行者,一步步登峯!