当前位置:网站首页>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://yzsam.com/2022/04/202204232017307463.html
边栏推荐
- Electron入门教程4 —— 切换应用的主题
- Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 64
- Compact CUDA tutorial - CUDA driver API
- R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
- An error is reported when sqoop imports data from Mysql to HDFS: sqlexception in nextkeyvalue
- Mysql database - basic operation of database and table (II)
- R language ggplot2 visualization: ggplot2 visualizes the scatter diagram and uses geom_ mark_ The ellipse function adds ellipses around data points of data clusters or data groups for annotation
- 论文写作 19: 会议论文与期刊论文的区别
- Numpy sort search count set
- Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (6)
猜你喜欢

PHP reference manual string (7.2000 words)

SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
Handwritten Google's first generation distributed computing framework MapReduce

Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (V)

Redis cache penetration, cache breakdown, cache avalanche

Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (6)

DNS cloud school | analysis of hidden tunnel attacks in the hidden corner of DNS

网络通信基础(局域网、广域网、IP地址、端口号、协议、封装、分用)

Project training of Software College of Shandong University - Innovation Training - network security shooting range experimental platform (VII)

SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
随机推荐
CVPR 2022 | QueryDet:使用级联稀疏query加速高分辨率下的小目标检测
SQL Server Connectors By Thread Pool | DTSQLServerTP 插件使用说明
[problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
How does onlyoffice solve no route to host
【数值预测案例】(3) LSTM 时间序列电量预测,附Tensorflow完整代码
PCA based geometric feature calculation of PCL point cloud processing (52)
论文写作 19: 会议论文与期刊论文的区别
The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
How about CICC fortune? Is it safe to open an account
Numpy mathematical function & logical function
Sqoop imports data from Mysql to HDFS using lzop compression format and reports NullPointerException
aqs的学习
Mysql database - single table query (II)
2022 - Data Warehouse - [time dimension table] - year, week and holiday
Remote code execution in Win 11 using wpad / PAC and JScript 1
PCL点云处理之计算两平面交线(五十一)
Leetcode dynamic planning training camp (1-5 days)
R语言使用caret包的preProcess函数进行数据预处理:对所有的数据列进行BoxCox变换处理(将非正态分布数据列转换为正态分布数据、不可以处理负数)、设置method参数为BoxCox
R语言ggplot2可视化分面图(facet_wrap)、使用lineheight参数自定义设置分面图标签栏(灰色标签栏)的高度
R语言survival包coxph函数构建cox回归模型、ggrisk包ggrisk函数和two_scatter函数可视化Cox回归的风险评分图、解读风险评分图、基于LIRI数据集(基因数据集)




