数据库存储
优点
- 大量数据
- 结构化数据
- 便于查询
SQLite数据库
- 小
- 嵌入式设备多
- 关系型数据库,以表的形式存储数据,行—记录 列–字段
- 遵循SQL标准
DDL增修改表
DDL数据库定义语言—创建表,修改字段,删除表
DML数据库操作语言—增加数据,更新数据,删除数据
DQL数据库查询语言—查询数据
DCL数据库控制语言—权限
创建表
数据类型
TEXT 字符串
INTEGER 整数
REAL 小数
BLOB 二进制,可存图片
NULL 空
create table表名(
字段名 数据类型[描述]
字段名 数据类型)
默认会给添加一列rowid
建议创建表的时候添加一列主键列_id
autoincrement 自动增长
create table stu(
_id integer primary key autoincrement,
name text,
age integer,
score real
)
修改表结构
增加列
alter table stu add column grade_name text
删除表
drop table book
DML增删改数据
增加数据
insert into 表名[(字段,字段,字段)] values(值,值,值)
insert into stu(name,age,score) values('白白',18,9905)
更新数据
update 表名 set 字段=值,字段=值[where 条件]
update stu set name='小王' where _id=2
删除数据
delete from 表名 [where 条件]
delete from stu where _id=2
DQL查询数据
select 字段,字段
from 表名
[where 条件]
select name,age from stu
--查询所有的数据
select * from stu
--关系运算符
--逻辑运算符
select * from stu where score>90
--between min小 and.max大
--包含边界
select * from stu where score between 60 and 80
--is null
--等于null
selsct * from stu where score is null
--不等于null
selsct * from stu where score is not null
--in(罗列一些值)是等值比较,不是范围
select * from stu where _id in(1,4)
--模糊查询
--like % 代表任意多个任意字符 _ 代表一个字符
select * from sti where name like '刘%'--姓刘就行
select * from sti where name like '刘_'--刘某
select * from sti where name like '_明'--某明
select * from sti where name like '%明'--名字以明结
select * from sti where name like '%明%'--中间带明的
--分页查询 limit size offset index
-- 多长 从哪开始
--index page第几页 index=(pager-1)*size
select * from stu limit 2 offset 0
--排序 order by 字段desc降序/asc升序
select * from stu order by _id asc
3457

被折叠的 条评论
为什么被折叠?



