如果你不想要使用mysql,Oracle这样的数据库,有想要实现数据存储,有没有解决方案?当然有,那就来看看sqlite3怎么操作的吧
常见命令
先从常见命令入手,熟悉下面的命令,有助于你快速上手sqlite3.
sqlite3 <*.db> //打开数据库
.help //显示所有命令
.quit //退出sqlite3:
.database //显示当前打开的数据库
.tables //显示数据库中所有表名
.schema [table_name] //查看表的结构
注意:这些命令都是以 ” . “开头的
sqlite常用语句
创建新表
create table <table_name> (f1 type1, f2 type2,…);
// 例如: create table people(id,name,age);
删除表
drop table <table_name>;
// 例如: drop table people;
添加记录
insert into <table_name> values (value1, value2,…);
// 例如: insert into people values(1,'A',10);
查询记录
select * from <table_name> where <expression>;
// 例如: select * from people where name='A';
删除记录
delete from <table_name> where <expression>;
// 例如: delete from pople where name='C';
更新记录
update <table_name> set <key=value>,… where <expression>;
// 例如: update people set name='wch' where id=4 and age=15;
在表中添加字段
alter table <table> add column <field> ;
// 例如: alter table people add column addr;