sqlite是一個小型的關系型數(shù)據(jù)庫绳锅。非常輕巧,方便酝掩。
自給自足鳞芙,無服務器,零配置是他強大之處期虾!
小型而又不缺乏關系型數(shù)據(jù)庫任何功能原朝,事務性。占用內存低只需要幾百k镶苞,處理速度快喳坠,比Mysql,PostgreSQL等主流數(shù)據(jù)庫都要快茂蚓,如果數(shù)據(jù)量不是特別龐大壕鹉,sqlite是最佳選擇剃幌。
安裝自行百度。很簡單
由于我安裝了anaconda御板,所以自帶了sqlite3锥忿。
基本操作
1、創(chuàng)建數(shù)據(jù)庫
sqlite3 mydatabase.db (mydata自己設置數(shù)據(jù)庫名稱)
2怠肋、創(chuàng)建表
create table mytable(id integer primary key,name text);
mytable 自己設置的表的名字
id name 自己設置的名稱 integer text 設置的類型
每一個操作的結尾必須以;結尾
primary key 主鍵設置
3淹朋、查看操作
.database 查看和管理數(shù)據(jù)庫
.tables 查看數(shù)據(jù)庫中的表
.schema table 查看表結構
4笙各、插入記錄
insert into mytable(id,name) values(NULL础芍,‘x’)杈抢;
NULL 表示自動設置 因為是主鍵會遞增
values(A,B) A和B為要設置的值
字符信息必須以‘ ’括起來仑性。
5惶楼、查看記錄
select * from mytable;
*表示所有信息
.mode column 以空格分開
.mode list 以|分開
.header on 顯示表頭(id诊杆,name)
6歼捐、刪除記錄
delete from mytable where id = 1;
7晨汹、更新記錄
update mytable set name = ‘c’ where id = 1豹储;
8、增加字段
alter table mytable add column email text not null default ‘’淘这;
9剥扣、刪除表
drop table mytable;
10铝穷、重命名
alter table newtable rename to mytable 钠怯;
重命名為newtable