当前位置:网站首页>数据库学习总结5
数据库学习总结5
2022-07-02 05:50:00 【目光还在捉迷藏81】
一、多表查询
1.语法:
select
列名列表
from
表名列表
where...
笛卡尔积: 有A,B两个集合,这两个集合的所有组成情况;
要完成多表查询,需要消除无用的数据
2.多表查询的分类
(1)内连接查询
首先确定好:
从那些表中查询数据
条件是什么
查询哪些字段
a.隐式内连接:使用where条件清除无用数据
select 字段列表 from 表名列表 where 表名1.`列名` = 表名2.`列名`;
两个表列名字段可能有重复,可以在列名前用表名打点来区分;
但是这样会很麻烦,可以给表起别名
select
t1.name,
t1.age,
t2.name
from
表名1 t1,
表名2 t2
where
t1.`列名` = t2.`列名`;
每个字段独占一行方便在后面加注释
b.显式内连接:
select 字段列表 from 表名1 【inner】 join 表名2 on 条件;
【inner 可以省略】
(2)外连接查询
a.左外连接:查询的是左表所有数据以及其交集部分
select 字段列表 from 表名1 left 【outer】 join 表名2 on 条件;
【outer 可以省略】
b.右外连接:查询的是左表所有数据以及其交集部分
select 字段列表 from 表名1 right 【outer】 join 表名2 on 条件;
【outer 可以省略】
(3)子查询:查询中嵌套查询
a.子查询的结果是单行单列的:
子查询可以作为条件,使用运算符去判断(>、<、>=、<=等单运算符)
b.子查询的结果是多行单列的:
子查询可以作为条件,使用运算符去判断( in 等逻辑运算符)
c.子查询的结果是多行多列的:
子查询可以作为一张虚拟表
二、事务
1.事务的基本介绍
(1)概念:如果一个包含多个步骤的业务操作,被事务管理,那么这些操作要么同时成功,要么同时失败。
(2)操作
a.开启事务:start transaction;
b.回滚:rollback;
c.提交:commit;
(3)事务提交的两种方式
a.自动提交:mysql就是自动提交的, 一条DML(增删改)语句会自动提交一次
b.手动提交:需要先开启事务再提交
(4)修改默认提交方式
a.查看默认提交方式:SELECT @@autocommit; -- 1 代表自动提交 -- 0 代表手动提交
b.修改默认提交方式:SET @@autocommit = 0;
2.事务的四大特征
(1)原子性:是不可分割的最小操作单位,要么同时成功,要么同时失败。
(2)持久性:当事务提交或回滚后,数据库会持久化的保存数据。
(3)隔离性:多个事物之间,相互独立。
(4)一致性:事务操作前后,数据总量不变。
3.事务的隔离级别(了解)
(1)概念:多个事务之间隔离的,相互独立的。但是如果多个事务同时操作同一批数据,则会引发一些问题,设置不同的隔离级别就可以解决这些问题
边栏推荐
- Fundamentals of software testing
- Test case
- GRBL 软件:简单解释的基础知识
- php读文件(读取文件内含有某字符串的指定行)
- 软件测试答疑篇
- [leetcode] day92 container with the most water
- Applet jumps to official account
- A collection of commonly used plug-ins for idea development tools
- Lantern Festival gift - plant vs zombie game (realized by Matlab)
- centos8安裝mysql8.0.22教程
猜你喜欢
Win10 copy files, save files... All need administrator permission, solution
“簡單”的無限魔方
Grbl software: basic knowledge of simple explanation
Thunder on the ground! Another domestic 5g chip comes out: surpass Huawei and lead the world in performance?
RGB 无限立方体(高级版)
15 C language advanced dynamic memory management
Alibaba: open source and self-developed liquid cooling data center technology
2022-2-14 learning xiangniuke project - Section 6 displays login information
Straighten elements (with transition animation)
测试 - 用例篇
随机推荐
Fabric. JS iText set italics manually
Installation du tutoriel MySQL 8.0.22 par centos8
Minimum value ruler method for the length of continuous subsequences whose sum is not less than s
线程池概述
死磕大屏UI,FineReport开发日记
A collection of commonly used plug-ins for idea development tools
PHP 开发与测试 Webservice(SOAP)-Win
正则表达式总结
Stick to the big screen UI, finereport development diary
Principle and implementation of parallax effect
我所理解的DRM显示框架
Software testing Q & A
TypeScript的泛型和泛型约束
vite如何兼容低版本浏览器
1036 Boys vs Girls
[golang syntax] be careful with the copy of slices
Matplotlib double Y axis + adjust legend position
centos8安裝mysql8.0.22教程
Lingyunguang rushes to the scientific innovation board: the annual accounts receivable reaches 800million. Dachen and Xiaomi are shareholders
Fabric. JS centered element