MySql数据库基本语句

绝大多数都是记忆练习的东西 理解的偏少
一,DML语句之Delete(删除)
格式:delete from 表单名; 其后可以增加where条件限制,order by排序,limit限制
例如:delete from employee where name=‘ls’; 删除表中名字为李四的记录。
还有一个删除是truncate
格式:Truncate table 表单名;
例如:Treuncate table employee;删除employee表单中所有数据。
注意:delete是一条一条的删除语句,效率比较低,而truncate是摧毁整张表格,然后重新建立表结构(表格依然存在,是空的),效率高
在入图片描述

二,DQL语句
Date Query Language 数据查询语言 用于查询数据库中的记录
关键字 select
语法:select 字节名 from 表单名;可以加where条件限制

select语句(1) 查询 过滤
语法:select [distinct] * from 表单名;
select [distinct] 字节名 from 表单名;
* 表示所有的列
distinct 表示 去除重复的数据
例如:查询表中所有学生信息
select * from student;
过滤表中重复的math成绩
select distinct math from student;

select语句(2) 修改

select * | 字节名1、字节名2 from 表单名;
select column as 别名 from table;
注意:字节名后可以加上加减乘除
as:表示给某一列起一个别名;并且as可以省略。
例如:使用别名表示学生的总分
select name,chinese+english+math as ‘总分’ from student;

select语句(3)
使用where限制条件进行过滤查询
例如:查询英语成绩大于90分的同学
select * from student where english>90;

select语句(4)
where语句中经常使用的运算符
between…and… 显示在某一区间的值(含头含尾)
in(set) 显示在in列表中的值,例:in(100,200)
like ‘’ 模糊查询 like语句中%代表0个或多个任意字符,_代表一个字符,字符要一一对应查询。
is null 判断是否为空
and 多个条件同时成立
or 多个条件任一成立
not 不成立
注意:逻辑运算符优先级 not and or
例如:查询所有姓L的学生成绩
select * from student where name like‘L%’;

select语句(5) 排序
使用order by子句对结果集进行排序
语法:select 字节1,字节2…from 表名 order by 字节 asc|desc;
注意:order by 字节 对那一列进行排序
asc 升序(默认) desc降序
例如:对总分排序后输出,然后再按从高到低的顺序输出
select name,chinese+english+math as total from student ORDER BY total desc;

select语句(6)
select 字节1,字节2…from 表名 limit_,_;
例如:显示student 表格中的前3行
Select * from student limit 3;
注意: 3 表示 显示前3行
显示 student 表格中的第3~5行
select * from student limit 2,3;
注意: 2表示偏移几行,3表示显示的总行数。

  • 5
    点赞
  • 29
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值