👨🎓作者:Java学术趴 🏦仓库:Github、Gitee ✏️博客:CSDN、掘金、InfoQ、云+社区 💌公众号:Java学术趴 🚫特别声明:原创不易,未经授权不得转载或抄袭,如需转载可联系小编授权。 🙏版权声明:文章里的部分文字或者图片来自于互联网以及百度百科,如有侵权请尽快联系小编。微信搜索公众号Java学术趴联系小编。
☠️每日毒鸡汤:太阳请不要晒黑我的皮肤,请晒黑我爸爸妈妈的头发。
👋大家好!我是你们的老朋友Java学术趴,今天继续给大家分享小编精心为大家整理的一万字MySQL数据库核心知识、在接下来的几天为大家持续分享,💘关注不迷路呦!!!💘。数据库是存放数据的仓库。它的存储空间很大,可以存放百万条、千万条、上亿条数据。但是数据库并不是随意地将数据进行存放,是有一定的规则的,否则查询的效率会很低。数据库是一个按数据结构来存储和管理数据的计算机软件系统。🦄
表:table是数据库的基本组成单元,所有的数据都以表格的形式组织,目的是可读性强。
DQL(数据查询语言):查询语句,凡是select语句都是DQL。
DML(数据操作语言):insert delete update ,对表当中的数据进行增删改。
DDL(数据定义语言):create drop alter ,对表结构进行增删改。
TCL(事务控制语言):commit提交事务,rollback回滚事务。(TCL中的T是 Transaction)
DCL(数据控制语言):grant授权、revoke撤销权限等。
以上三张表格分别是:(部门表、员工表、工资等级表)
注意:补充sql脚本知识。
在这张表中存在(部门编号) (部门名称)(部门位置)信息(结构)
(员工编号)(员工姓名)(工作岗位(上级领导编号)(入职时间)(月薪)(补助/津贴 (部门编号)
以上表中包含(工资等级)(最低薪资)(最高薪资)
语法格式: select 字段名1,字段名2,字段名3,…from 表名;
select ename,sal * 12 from emp;
select ename,sal * 12 as yearsal from emp; // 取的为英文名字
select ename,sal * 12 as ‘年薪’ from emp; // 取的为中文名字
注意:Mysql 中字符串可以使用 单引号 或者 双引号 括起来 而在 oracle 中字符串只能使用 单引号 括起来 建议以后都使用单引号括起来。
重点:语句中的as可以省略不写。
select ename,sal * 12 ‘年薪’ from emp;
1.5.1 查询一个字段
select ename from emp;
1.5.2 查询多个字段
select ename.sal from emp;
1.5.3 查询全部字段
select * from emp; (不建议使用,代表全部字段,要将装换为全部字段,效率低)
select
字段1,字段2...
from
表名
where
条件;
执行顺序:先from ,然后where,最后select
select ename from emp where sal = 5000;
select sal from emp where ename = ‘SMITH’; // 字符串用单引号括起来
select ename,sal from emp where sal > 3000;
select ename,sal from emp where sal >= 3000;
select ename,sal from emp where sal < 3000;
select ename,sal from emp where sal <= 3000;
select ename,sal from emp where sal <> 3000;
select ename,sal from emp where sal != 3000;
注意:不等于可以是 <> 或者 != ,两个都可以的。
select ename,sal from emp where sal >=1100 and sal <= 3000; // 使用的是 and
select ename,sal from emp where sal between 1100 and 3000;
字符串使用 between…and… 判断的是字符串的第一个字符,所得的结果是左闭右开区间 [a,b)
select ename from emp where ename between ‘A’ and ‘B’;
注意: 在数据库当中NULL不是一个值,代表什么都没有,为空。 空不是一个值,不能用等号衡量。 必须使用 is null 或者 is not null 0.0 也属于 NUll ,他代表 0 数值。
select ename,comm from emp where comm = null; //错误写法,不能进行赋值。
select ename,comm from emp where comm is null; // 正确的写法
select ename,sal,comm from emp where comm is not null;
select ename,sal,comm from emp where comm is null or comm = 0;
select ename,job from emp where job = ‘MANAGER’ or job = ‘SALESMAN’;
select ename,sal,deptno from emp where sal > 1000 and (deptno = 20 or deptno = 30);
注意: 当运算符的优先级不确定的时候,可以加括号调整计算顺序。
select ename,job from emp where job = ‘MANAGER’ or job=‘SALESMAN’; select ename,job from emp where job in(‘MANAGER’,‘SALESMAN’);
注意:in后面的值不是区间,是具体的值。
select ename,job from emp where sal in(800,5000);
select ename,job,sal from emp where sal not in(800,5000);
select ename from emp where ename like “%o%”;
select ename from emp where ename like ‘_A%’;
select ename from emp where ename like ‘%_%’;
注意: 此时 _ 代表一个普通的 下划线 _
select ename from emp where ename like ‘%T’;
今天就先分享到这里,明天继续给大家分享,关注不迷路呦,我们明天见😊。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。