当前位置:网站首页>3. Transactions and views
3. Transactions and views
2022-04-21 07:11:00 【smile_ pbb】
One 、 Business
1. Concept
One or a group of sql Statements form an execution unit , This execution unit is either all executed , Or none at all . If one of a group sql Once the execution fails or an error occurs , The whole group sql Statements are rolled back . All changed data will also return to the state before the start of the transaction .
2. Storage engine
mysql> show engines;
InnoDB Storage engine support transactions .MyISAM 、MEMORY I won't support it
3. Characteristics of the transaction
3.1 Atomicity
Refer to A transaction is an indivisible unit of work , All operations in a transaction are either performed , Either not
3.2 Uniformity
Transactions must transform the database from one consistency state to another
3.3 Isolation,
Refer to The execution of one transaction cannot be disturbed by other transactions
3.4 persistence
Once a transaction is committed , It changes the data in the database permanently .
Two 、 The transaction operations
1. Implicit transaction
Transactions have no obvious start and end marks . such as insert update delete
mysql Auto submit in is automatically turned on .
mysql> show variables like 'autocommit';
2. According to the transaction
A transaction has distinct open and end tags .
# Turn off the auto commit transaction function . You can start a transaction without turning off auto commit
mysql> set autocommit=0;
Query OK, 0 rows affected (0.00 sec)
mysql> show variables like 'autocommit';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| autocommit | OFF |
+---------------+-------+
1 row in set (0.00 sec)
3. Operation of transaction
begin : Start a transaction
commit : Commit a transaction
rollback : Roll back a transaction
example :
mysql> create database pangbing;
mysql> use pangbing
mysql> create table abc (name char(20),nianling int(3));
mysql> show tables;
+--------------------+
| Tables_in_pangbing |
+--------------------+
| abc |
+--------------------+
1 row in set (0.00 sec)
mysql> insert into abc values ('a',20);
Query OK, 1 row affected (0.01 sec)
mysql> select * from abc;
+------+----------+
| name | nianling |
+------+----------+
| a | 20 |
+------+----------+
1 row in set (0.00 sec)
mysql> begin;
Query OK, 0 rows affected (0.00 sec)
mysql> insert into abc values ('b',18);
mysql> insert into abc values ('c',22);
mysql> select * from abc;
+------+----------+
| name | nianling |
+------+----------+
| a | 20 |
| b | 18 |
| c | 22 |
+------+----------+
3 rows in set (0.00 sec)
# Roll back the transaction
mysql> rollback;
Query OK, 0 rows affected (0.00 sec)
mysql> select * from abc;
+------+----------+
| name | nianling |
+------+----------+
| a | 20 |
+------+----------+
1 row in set (0.00 sec)
Pay attention to is : To roll back a transaction , Cannot commit transaction , Commit transactions cannot be rolled back .mysql The default is auto submit .
# Commit transaction
mysql> commit;
3、 ... and 、 View
A view is a virtual table , Use the same method as the table
grammar :
create view View name as sql sentence ;
mysql> select * from abc where name='a';
+------+----------+
| name | nianling |
+------+----------+
| a | 20 |
+------+----------+
# Create a view
mysql> create view shitu as select * from abc where name='a';
Query OK, 0 rows affected (0.00 sec)
# Use view
mysql> select * from shitu;
+------+----------+
| name | nianling |
+------+----------+
| a | 20 |
+------+----------+
1 row in set (0.00 sec)
版权声明
本文为[smile_ pbb]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204210611532127.html
边栏推荐
- CISSP认证每日知识点(2022年4月13日)
- ESP32 LVGL8.1 ——event 事件 (event 17)
- ESP32 LVGL8.1 ——bar 进度条 (bar 21)
- jvm 的 解释执行与 编译执行
- canvas 绘制路飞
- Modify the launcher3 icon and add a mask or shadow icon to the icon
- QT error: no matching member function for call to ‘connect‘
- 每日网安认证测试题(2022年4月14日)
- Using numpy library to realize convolution network from scratch and complete the recognition of MNIST handwritten data set
- How to package idea into war package
猜你喜欢

Learn SCI paper drawing skills (a)

How does excel form become latex format?

将QT默认控件提升为自定义控件

How to package idea into war package

logstash 7.x 中时间问题,@timestamp 与本地时间相差 8个小时

"Fundamentals of digital electronic technology" 4.3 learning notes of some commonly used combinational logic circuits

Draw biaxial separation diagram with ggplot2

How to download and use the journal latex template

Detailed steps and explanation of converting MNIST data into numpy array format

I2C protocol (I): I2C bus spec
随机推荐
2、 1 [FPGA] initial FPGA
2、 2 [FPGA] development environment construction
ESP32 LVGL8.1 ——anim 动画 (anim 16)
2. mysql基本查询
win10 系统重装后,如何恢复mysql 数据库(mysql-8.0.26-winx64.zip)
2、 Signal filtering > mean filtering and median filtering
Li Kou video note 21 - depth first search method + 938 question method
MATLAB data normalization function
【SSM整合】4. 逻辑代码编写以及测试
【Labview】记录下做Labview项目的一些坑点
I2C protocol (I): I2C bus spec
GD单片机Keil环境搭建
ESP32 LVGL8.1 ——bar 进度条 (bar 21)
Launcher3 secondary development modification removes drawers, displays icons in workspace, deletes Google search box and other operations.
CANopen STM32移植
QT 曲线/示波器 customplot控件
MySQL数据库备份命令--mysqldump
imx6网口上电后连接不稳定link up,link down
Flat (flat lattice transformer) code implementation
CANopen使用方法与对象字典主要参数