第一步:
建立一个数据库,例如建立一个data.db的数据库。在命令行输入sqlite3 data.db。
第二步:
有了数据库就要建立一个表。在sqlite3命令行输入create table <表名> (字段1,字段2,。。。。。。);
例如建立create table mytable (id integer primary key,name text)。这句话是建立一个名为mytable的表字段1为ID,字段2为name,ID为主键
第三步:
有了表格就要往里面加数据。insert into 表名 (column_list )values ({ expression } [ ,...n] )
例如添加 insert into mytable (id ,name) values (1,'zhangsan');
第四步:
显示数据 select * from 表名;
例如 select * from mytable;
第五步:
更改数据 update 表名 set 字段 = 数据 where 字段 = 数据;
例如 update mytable set name = ‘liang’ where id = 3;
第六步:
删除数据 delete from 表名 where 字段 = 数据;
例如delete from mytable where ID = 2;
第七步:
增加表的列数 alter table 表名 add column 字段 text not NULL default ‘’;
例如增加一个email的列 alter table mytable add column email text not NULL default ‘’;
第八步:
删除表 drop table 表名;