当前位置:网站首页>数据库学习总结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)概念:多个事务之间隔离的,相互独立的。但是如果多个事务同时操作同一批数据,则会引发一些问题,设置不同的隔离级别就可以解决这些问题
边栏推荐
- A collection of commonly used plug-ins for idea development tools
- Stick to the big screen UI, finereport development diary
- Importation de studio visuel
- Go language web development is very simple: use templates to separate views from logic
- XSS basic content learning (continuous update)
- js判断移动端还是pc端
- OLED12864 液晶屏
- Oled12864 LCD screen
- H5 jump applet
- 【论文翻译】GCNet: Non-local Networks Meet Squeeze-Excitation Networks and Beyond
猜你喜欢

all3dp. All Arduino projects in com website (2022.7.1)

kmp思想及模板代码

Centos8 installation mysql8.0.22 tutorial

Record sentry's path of stepping on the pit

如何写出好代码 — 防御式编程指南

5g market trend in 2020

在线音乐播放器app

Appnuim environment configuration and basic knowledge

Installation du tutoriel MySQL 8.0.22 par centos8

mysql的约束总结
随机推荐
Visual Studio导入
Record sentry's path of stepping on the pit
2022-2-14 learning xiangniuke project - Section 7 account setting
Innovation never stops -- the innovation process of nvisual network visualization platform for Excel import
RGB infinite cube (advanced version)
Fabric. JS three methods of changing pictures (including changing pictures in the group and caching)
Zzuli:1066 character classification statistics
Win10 copy files, save files... All need administrator permission, solution
Zzuli: maximum Convention and minimum common multiple
Fundamentals of software testing
php读文件(读取文件内含有某字符串的指定行)
Vite打包后的dist不能直接在浏览器打开吗
brew install * 失败,解决方法
[personal test] copy and paste code between VirtualBox virtual machine and local
Simply encapsulate JS and apply it
5g market trend in 2020
Fabric. JS round brush
RGB 无限立方体(高级版)
Zzuli:1065 count the number of numeric characters
Fabric. JS activation input box