增
使用命令 insert into DBName(Field1,Field2…) values(Value1,Value2…); 插入数据
insert into student(_id,name,age) values(1,"tom",18);
添加所有数据可省略字段名
insert into student values(2,"john",19);
添加部分数据,只指定对应列(未添加的列为NULL)
insert into student(name,age) values("steve",20);
插入中文数据报错:MySQL5.6中文插入乱码问题处理
查
全部查询
使用命令 select * from DBName; 查询所有数据
select * from student;
根据条件查询
between查询
select * from student where age >=19 and age <=20;
select * from student where age between 19 and 20;
in查询
select * from student where age =19 or age =20;
select * from student where age in(19,20);
筛选字段查询
select name from student;
根据排序查询
asc升序,desc降序
select * from student order by age asc;
起别名查询
select name as "名字", age as "年龄" from student;
模糊查询
查询以t开头的name
select * from student where name like "t%";
查询以t开头,名字为3字符的name
select * from student where name like "t__";
改
使用命令 update DBName set Field = Value (where Condition)修改字段
update student set age=20 where name = "tom";
update student set age=0 where _id is null;
删
使用命令 delete from DBName (where Condition);
delete from student where age=21;