【金秋打卡】第1天+重回SQL的怀抱
2022/10/26 3:24:58
本文主要是介绍【金秋打卡】第1天+重回SQL的怀抱,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
课程名称
全能软件测试工程师
课程章节
MySQL基本操作
课程讲师
大周
课程内容
主要学习 MySQL的增删改查基本操作
插入
insert into 表名(字段名1,字段名2……) value (值1,值1……), (值1,值1……), (值1,值1……);
删除
- 删除表中全部数据
drop from 表名
- 按条件删除表中部分数据
delete from 表名 where 字段名=字段值
- 清空表中数据(真的删除数据,不会在日志中保留记录)
truncate table 表名
- 删除表
drop table 表名
注意:
5. 清空表:delete
操作
6. 截断表:truncate
操作
更新
- 数据更新(全部),示例:
update 表名 set 列1=新值1,列2=新值2 update user set sex=0;
- 按条件更新数据,示例:
update 表名 set 列1=新值1,列2=新值2 where 过滤条件
- 同时更新指定两个数据,示例(注意or的使用):
update user set sex=1 where user_name='小强' or user_name='韩梅梅'
- 同时更新多个字段,示例:
update 表名 set 列1=新值1,列2=新值2 where 过滤条件
查询
- 简单查询与别名
select name as student_name from 表名
- 单条件查询
select * from 表名 where 字段名=字段值
- 模糊查询
前模糊:select * from 表名 where 字段名 like "%关键字" 中间模糊:select * from 表名 where 字段名 like "关键字%关键字" 后模糊:select * from 表名 where 字段名 like "关键字%" 限制字符模糊查询:select * from 表名 where 字段名 like "关键字_"
注意:下划线_
表示替代一个字符,%
代表替代 0 个或多个字符
- 数据筛选查询
- 大于: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条数据)
- 多条件查询
使用布尔逻辑运算符:and、or可实现多条件查询,同时对于优先级可使用()
来进行自主限定
课程收获
通过对本章节的学习,基本熟悉了SQL语法和简单的增删改查操作,唤醒了尘封的SQL学习记忆。
这篇关于【金秋打卡】第1天+重回SQL的怀抱的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-20测试人员都是画画大神,让我看看谁还不会用代码图?
- 2024-05-20年薪百万的程序员都在用的摸鱼方式……
- 2024-05-19永别了,微服务架构!
- 2024-05-15鸿蒙生态设备数量超8亿台
- 2024-05-13TiDB + ES:转转业财系统亿级数据存储优化实践
- 2024-05-09“2024鸿蒙零基础快速实战-仿抖音App开发(ArkTS版)”实战课程已上线
- 2024-05-09聊聊如何通过arthas-tunnel-server来远程管理所有需要arthas监控的应用
- 2024-05-09log4j2这么配就对了
- 2024-05-09nginx修改Content-Type
- 2024-05-09Redis多数据源,看这篇就够了