数据库之增删改查
在安卓开发中Sqlite数据库是必学知识,一旦提起数据库,就不得不提数据库的增删改查等基本语句
创建数据表
- create table Tab_name (字段1 数据类型,字段2 数据类型,字段3 数据类型…);
删除数据表
- drop Tab_name;
增
- insert into Tab_name (字段列表) values (值列表);
删
- delete from Tab_name where [条件];
改
- update Tab_name set 字段 = 值,字段 = 值,字段 = 值 where [];
查
- select 字段列表 from Tab_name where [];
例子:
- Create TABLE teacher(workId text PRIMARY Key,name text,sex text,belongClass int);
- insert into teacher (workId,name,sex,belongClass)values(‘10010’,‘王德发’,‘男’,2018);
- insert into student(number,name,sex,age,address)values(null,‘赵四’,‘男’,null,null);
- delete from student where name=‘赵四’;
- delete from student where age=‘18’;
- insert into teacher(workId,name,sex,belongClass)values(‘100861’,‘刘老师’,‘男’,2);
- select * from teacher ;
- insert into teacher (workId,name,sex,belongClass)values(‘10011’,‘刘庆’,‘女’,2018);
- update teacher set name=‘张三’ where name =‘刘巧巧’;
- update teacher set name = ‘张瑷’ where workId =‘10012’;