首页 > 系统 > Android > 正文

Android基础SQLite知识

2019-11-07 22:56:14
字体:
来源:转载
供稿:网友

Android基础SQLite知识

1、sqlite数据库数据类型

Integer  varchar (10)  float  double char(10)  text 

2、sql 语句回顾

2.1 创建表的语句

create table 表名 (字段名称  数据类型 约束 , 字段名称  数据类型 约束 ,…………)

create table person ( _id Integer  PRimary key  ,   name varchar(10) , age Integer  not null)

2.2 删除表的语句

drop table 表名

drop table person

2.3 插入数据

insert into 表名【字段,字段】 values (值1 , 值2)

insert into person (_id ,age ) values ( 1 , 20 )       //指定字段

insert into person  values ( 2 ,"zs" , 30 )    // 不指定字段,按建表语句,依次填入相应数据

2.4 修改数据

update 表名 set 字段= 新值 where 修改的条件

update person set  name = "ls" , age = 20  where _id = 1      // 没有where条件,表示修改全部数据

2.5 删除数据

delete from 表名 where 删除的条件

delete from person where _id = 2

2.6、 查询语句

select  字段名 from 表名 where 查询条件 group by 分组的字段  having 筛选的提交  order by  排序字段

select * from  person;   查询所有数据

select  _id  , name from person ;  查询ID 和 name 两个字段

select * from person where _id = 1 ;

select  *  from  person where _id <>1   ;    查询id 不等于 1 的数据

select * from person where _id =1 and  age > 18 ;  多条件查询 用and 连接

select * from person where name like "%小%"  查询名字中,前后包含任意多字符。中间带小的数据

select * from person where name like "_小%"  查询一个字符之后就是 “小”,后面可以有任意多字符的数据。

select * from person where name is null    查询名字为null 的数据

select * from person where age  between 10 and 20  年龄在10到20之间的数据

select * from person where age > 18 order  by  _id   直接排序


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表