当前位置:网站首页>16MySQL之DCL 中 COMMIT和ROllBACK
16MySQL之DCL 中 COMMIT和ROllBACK
2022-04-23 20:17:00 【gh-xiaohe】
文章目录
作者: gh-xiaohe
gh-xiaohe的博客
觉得博主文章写的不错的话,希望大家三连(关注,点赞,评论),多多支持一下!!
DCL 中 COMMIT和ROllBACK
DCL 中 COMMIT和ROllBACK
COMMIT
COMMIT:提交数据。一旦执行COMMIT,则数据就被永久的保存在了数据库中,意味着数据不可以回滚。
ROLLBACK
ROLLBACK:回滚数据。一旦执行ROLLBACK,则可以实现数据的回滚。回滚到最近的一次COMMIT之后。
对比
- 相同点:都可以实现对表中所有数据的删除,同时保留表结构。
- 不同点:
- TRUNCATE TABLE:一旦执行此操作,表数据全部清除。同时,数据是不可以回滚的。
- DELETE FROM:一旦执行此操作,表数据可以全部清除(不带WHERE)。同时,数据是可以实现回滚的。
DDL 和 DML 的说明
① DDL的操作一旦执行,就不可回滚。指令SET autocommit = FALSE对DDL操作失效。(因为在执行完DDL操作之后,一定会执行一次COMMIT。而此COMMIT操作不受SET autocommit = FALSE影响的。)
② DML的操作默认情况,一旦执行,也是不可回滚的。但是,如果在执行DML之前,执行了 SET autocommit = FALSE,则执行的DML操作就可以实现回滚。
案例
COMMIT、DELETE
# 演示:DELETE FROM #1) COMMIT; #2) SELECT * FROM myemp3; #3) SET autocommit = FALSE; #4) DELETE FROM myemp3; #5) SELECT * FROM myemp3; #6) ROLLBACK; #7) SELECT * FROM myemp3;
COMMIT、 ROLLBACK
# 演示:TRUNCATE TABLE #1) COMMIT; #2) SELECT * FROM myemp3; #3) SET autocommit = FALSE; #4) TRUNCATE TABLE myemp3; #5) SELECT * FROM myemp3; #6) ROLLBACK; #7) SELECT * FROM myemp3;
MySQL8.0的新特性:DDL的原子化
在MySQL 8.0版本中,InnoDB表的DDL支持事务完整性,即DDL操作要么成功要么回滚。DDL操作回滚日志写入到data dictionary数据字典表mysql.innodb_ddl_log(该表是隐藏的表,通过show tables无法看到)中,用于回滚操作。通过设置参数,可将DDL操作日志打印输出到MySQL错误日志中。
分别在MySQL 5.7版本和MySQL 8.0版本中创建数据库和数据表,结果如下:
CREATE DATABASE mytest; # 创建数据库 mytest USE mytest; # 切换到 mytest 数据库下 CREATE TABLE book1( # 创建 book1 表 book_id INT , book_name VARCHAR(255) ); SHOW TABLES; # 查看当前数据下的表
(1)在MySQL 5.7版本中,测试步骤如下:
# 在 mysql5.7 下 DROP TABLE book1,book2; # 此时删除数据库 book1 和 book2 注意此时没有 book2 SHOW TABLES;
(2)在MySQL 8.0版本中,测试步骤如下:
# 在 mysql8.0 下 DROP TABLE book1,book2; # 此时删除数据库 book1 和 book2 注意此时没有 book2 SHOW TABLES;
版权声明
本文为[gh-xiaohe]所创,转载请带上原文链接,感谢
https://blog.csdn.net/gh_xiaohe/article/details/124314094
边栏推荐
- 如何在BNB鏈上創建BEP-20通證
- [text classification cases] (4) RNN and LSTM film evaluation Tendency Classification, with tensorflow complete code attached
- R语言使用timeROC包计算存在竞争风险情况下的生存资料多时间AUC值、使用cox模型、并添加协变量、R语言使用timeROC包的plotAUCcurve函数可视化多时间生存资料的AUC曲线
- Leetcode XOR operation
- Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (6)
- 2022 - Data Warehouse - [time dimension table] - year, week and holiday
- Tencent Qiu Dongyang: techniques and ways of accelerating deep model reasoning
- Local call feign interface message 404
- Alicloud: could not connect to SMTP host: SMTP 163.com, port: 25
- Electron入门教程3 ——进程通信
猜你喜欢
Numpy - creation of data type and array
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
Operation of numpy array
PHP reference manual string (7.2000 words)
MySQL 进阶 锁 -- MySQL锁概述、MySQL锁的分类:全局锁(数据备份)、表级锁(表共享读锁、表独占写锁、元数据锁、意向锁)、行级锁(行锁、间隙锁、临键锁)
[numerical prediction case] (3) LSTM time series electricity quantity prediction, with tensorflow complete code attached
程序设计语言基础(2)
After route link navigation, the sub page does not display the navigation style problem
如何在BNB鏈上創建BEP-20通證
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
随机推荐
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
Remote code execution in Win 11 using wpad / PAC and JScript
Notes of Tang Shu's grammar class in postgraduate entrance examination English
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数和two_scatter函数可视化Cox回归的风险评分图、解读风险评分图、基于LIRI数据集(基因数据集)
Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)
nc基础用法2
Record: call mapper to report null pointer Foreach > the usage of not removing repetition;
Leetcode XOR operation
Building googlenet neural network based on pytorch for flower recognition
Change the material of unity model as a whole
STM32 Basics
JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
R language ggplot2 visual facet_wrap, and use the lineheight parameter to customize the height of the facet icon tab (gray label bar)
Mysql database - basic operation of database and table (II)
WordPress插件:WP-China-Yes解决国内访问官网慢的方法
Wave field Dao new species end up, how does usdd break the situation and stabilize the currency market?
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行BoxCox变换处理(将非正态分布数据列转换为正态分布数据、不可以处理负数)、设置method参数为BoxCox
AQS learning
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(八)