当前位置:网站首页>mysql事务的引入
mysql事务的引入
2022-07-26 00:10:00 【Camellia——】
-- 事务:将整个业务操作使用事物管理起来,整个事务的执行要么同时成功,要么同时失败,如果中间出现异常,事物回滚,整个事物将执行失败!
-- (将整个业务操作看成一个整体,使用事物管理起来)
-- 对于DML语句的增删改,默认自动提交SELECT @@autocommit;-- 查看当前事物的状态:自动提交(1)
-- 模拟转账操作
-- 创建一个账户表,id账户编号,自增长的主键
-- name 账户名
-- balance 金额
CREATE TABLE account(
id INT PRIMARY KEY AUTO_INCREMENT,
NAME VARCHAR(10),
balance INT
);
SELECT *FROM account;-- 插入两条数据
INSERT INTO account(NAME,balance)VALUES('李四',1000),('王五',1000);
-- 如何开启手动提交事务 start transaction;如果转账中间出现问题了,回滚:rollback;
-- 整个语句执行完毕(如果没有问题) commit;提交事务
START TRANSACTION;
-- 李四-500
UPDATE account SET balance=balance-500 WHERE id=1;
转账出问题了
-- 王五+500
UPDATE account SET balance=balance+500 WHERE id=2;
-- 回滚到回滚点(将业务的执行还原到最开始的状态)
ROLLBACK;
边栏推荐
- Leetcode200 - find detailed explanation of the number of islands
- Thymeleaf view integration
- After using MQ message oriented middleware, I began to regret
- Stack and queue - 347. Top k high frequency elements
- markdown写作平台
- 网站服务器停止响应是什么意思?
- "Animal coin" is fierce, trap or opportunity? 2021-05-12
- Binary tree -- 700. Search in binary search tree
- Android solves the risk of database injection vulnerability
- Jd.com API for obtaining recommended product list
猜你喜欢

MySQL - database log

MySQL——主从复制

Sequence traversal II of leetcode107 binary tree

The bull market will continue. Take your money 2021-05-08

牛血清蛋白修饰酚酸类及生物碱类小分子/偶联微球的蛋白/牛红细胞SOD的研究

Unity -- Euler angle, quaternion

06_ UE4 advanced_ Set up a large map using the terrain tool

Representation and implementation of stack (C language)

Backtracking - 17. Letter combinations of phone numbers

Nest.js 用了 Express 但也没完全用
随机推荐
How to make your JS code more beautiful
计算物理期刊修改
FreeRTOS personal notes - semaphore
The bull market will continue. Take your money 2021-05-08
NVIDIA可编程推理加速器TensorRT学习笔记(三)——加速推理
滑动窗口_
Module II operation
Solid smart contract development - 3.2-solid syntax array, structure, mapping
FreeRTOS personal notes - message queue
SHIB(柴犬币)一月涨幅数百倍,百倍币需具备哪些核心要素?2021-05-09
C language actual combat guessing game
网站服务器停止响应是什么意思?
07_ue4进阶_发射火球扣mp值和攻击扣血机制
Unity -- Euler angle, quaternion
多任务编程
LeetCode_55_跳跃游戏
什么是 Web3 游戏?
CountDownLatch
FreeRTOS个人笔记-互斥量
Niuke / Luogu - [noip2003 popularization group] stack