添加数据
语法:insert into 表名 (列名1, )values()
删除数据:
语法:delete from 表名[where 条件]
如果不加条件就会删除所有的数据
truncate table 表名 删除现在的表再创建一个一摸一样的空表
delete from 表名 直接删除表 表内有多少条记录就会执行多少次删除操作
修改数据
update 表名 set 列名1=值1,列名2=值2,.......[where 条件]
如果不加任何条件将会将表中所有数据全部修改
DQL 查询表中的记录
select * from表名;
语法:
select
字段列表
from
表名列表
where
条件列表
group by
分组字段
having
分组之后的条件
order by
排序
limit
分页限定
基础查询
多个字段的查询 select 列名1,列名2,......from 表名
去除重复 select distinct 列名from表名;
计算列 select name,math,english,ifnull(math+english,0) from student
起别名 select name,math,english,ifnull(math+english,0)as 总分 from student
或者select name,math,english,ifnull(math+english,0) 总分 from student 总分前加空格
条件查询
where 字句后加条件
运算符
<,>,>=,<=,=
between...and
in(集合)
like
is null
and或&&
or或 ||
not或!
null值不能使用=(!=)判断
where english is null;
where english is not null;
like 模糊查询
占位符:
_ 单个任意字符
%多个任意字符
select *from student where name like '马%'
select *from student where name like '_化%'
浙公网安备 33010602011771号