1.事务: 多条数据库操作语句DML DQL同时成功或同时失败
参考文章:https://blog.csdn.net/Jocker_D/article/details/87384673
原子性:成功都成功,失败都失败 一致性:多用户数据一致 持久性:事务提交或未提交前后数据 隔离性: 多用户互不影响
mysql 默认自动开启事务 set autocommit=0;关闭 set autocommit=1;开启 创建事务: set autocommit=0 --关闭事务自动提交 start transaction---事务开启 select... insert into... update table set delete from..where.. --- 操作动作 commit ---提交事务 rollback --提交失败回滚 set autocommit=1 ---手动开启事务 savepoint 保存点 rollback to savepoint ---回滚到保存点 release savepoint ----撤销保存点 ===================================== create database if not exists D character set utf8 collate utf8_general_ci; use D; create table if not exists `account`( `id` int(3) not null auto_increment, `name` varchar(30) not null, `money` decimal(9,2) not null, primary key (`id`) )engine = innodb default charset=utf8; insert into account(name,money)value(‘A‘,2000.00),(‘B‘,10000.00); set autocommit=0;--关闭自动提交 start transaction --开启事务 update account set money=money-500 where name=‘A‘; update account set money=money+500 where name=‘B‘; commit;--提交所有操作 rollback;--失败回滚 set autocommit=1;--恢复自动提交
原文地址:https://www.cnblogs.com/chencn/p/12303862.html
时间: 2024-10-20 12:25:38