继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

【金秋打卡】第1天+重回SQL的怀抱

是东潮啊
关注TA
已关注
手记 14
粉丝 0
获赞 2

课程名称

全能软件测试工程师

课程章节

MySQL基本操作

课程讲师

大周

课程内容

主要学习 MySQL的增删改查基本操作

插入

insert into 表名(字段名1,字段名2……)
value
(1,值1……),
(1,值1……),
(1,值1……);

删除

  1. 删除表中全部数据
drop from 表名
  1. 按条件删除表中部分数据
delete from 表名 where 字段名=字段值
  1. 清空表中数据(真的删除数据,不会在日志中保留记录)
truncate table 表名
  1. 删除表
drop table 表名

注意:
5. 清空表:delete操作
6. 截断表:truncate操作

更新

  1. 数据更新(全部),示例:
update 表名 
set1=新值1,2=新值2
update user 
set sex=0;
  1. 按条件更新数据,示例:
update 表名 
set1=新值1,2=新值2 
where 过滤条件
  1. 同时更新指定两个数据,示例(注意or的使用):
update user 
set sex=1
where user_name='小强' or user_name='韩梅梅'
  1. 同时更新多个字段,示例:
update 表名 
set1=新值1,列2=新值2
where 过滤条件

查询

  1. 简单查询与别名
select name as student_name  from 表名
  1. 单条件查询
select * from 表名 where 字段名=字段值
  1. 模糊查询
前模糊:select * from 表名 where 字段名 like "%关键字"
中间模糊:select * from 表名 where 字段名 like "关键字%关键字"
后模糊:select * from 表名 where 字段名 like "关键字%"
限制字符模糊查询:select * from 表名 where 字段名 like "关键字_"

注意:下划线_表示替代一个字符,%代表替代 0 个或多个字符

  1. 数据筛选查询
 - 大于:select * from 表名 where score > 100
 - 大于等于:select * from 表名 where score >= 100
 - 小于:select * from 表名 where score < 100
 - 小于等于:select * from 表名 where score <= 100
 - null:select * from 表名 where score is null
 - 空字符串:select * from 表名 where score = ""
 - 不为null:select * from 表名 where score is not null
 - 不等于: <> or !
 - 包含in:select * from 表名 where score in (30,40,50)
 - 不包含in:select * from 表名 where score not in (30,40,50)
 - 两者之间:select * from 表名 where score between 90 and 150(即包含90,又包含100)
 - 返回指定条数:select * from 表名 where score in (30,40,50) limit 3(返回前3条数据)
  1. 多条件查询
    使用布尔逻辑运算符:and、or可实现多条件查询,同时对于优先级可使用()
    来进行自主限定

课程收获

通过对本章节的学习,基本熟悉了SQL语法和简单的增删改查操作,唤醒了尘封的SQL学习记忆。
图片描述

打开App,阅读手记
1人推荐
发表评论
随时随地看视频慕课网APP