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

2022/10/26 3:24:58

本文主要是介绍【金秋打卡】第1天+重回SQL的怀抱,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

课程名称

全能软件测试工程师

课程章节

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 表名 
set 列1=新值1,列2=新值2
update user 
set sex=0;
  1. 按条件更新数据,示例:
update 表名 
set 列1=新值1,列2=新值2 
where 过滤条件
  1. 同时更新指定两个数据,示例(注意or的使用):
update user 
set sex=1
where user_name='小强' or user_name='韩梅梅'
  1. 同时更新多个字段,示例:
update 表名 
set 列1=新值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学习记忆。
图片描述



这篇关于【金秋打卡】第1天+重回SQL的怀抱的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程