一.表操作:
1.创建一个表名为Person,id, age ,msg 三个字段
create table Person(id INTEGER primary key autoincrement,age int,name text )
不存在才创建表
create table if not exists Person(id INTEGER primary key autoincrement,age int,name text )
"create table 表名("
+"id integer primary key autoincrement,"
+"name varchar(20),"//***************************varchar(20)或者char(20),price real(实数),page integer(int 类)等等
+"author char(8))";
再执行语句db.execSQL(SQL);
varchar(5)和char(5)都是数据库中用来修饰字符型的数据,char(5)代表固定长度为5的字符串,varchar(5)代表最大长度为5的字符串;
2.查询数据库下所有表的信息
select * from sqlite_master where type='table' order by name
3.查询数据表名为Person的信息
select * from sqlite_master where type='table' and name = 'Person'
4.删除表
drop table if exists Person
5.往表中新增字段
ALTER TABLE Person ADD COLUMN JOB VARCHAR(60)
二.查询数据
1.where用法
select * from Person where name = '小红'
2.like用法
表示某个字段数据中是否含有此值
查询Person表中name中带有‘小’字的数据
select * from Person where name like '%小%'
3.order by 排序
默认正序asc
select * from Person order by id asc
倒序desc
select * from Person order by id desc
4.查询表中所有数据
select * from Person
5.查询数据总数
select count(*) as total from Person