【知识库】--mysql COMMIT and ROLLBACK --AUTOCOMMIT(196)

本文介绍了MySQL中如何使用COMMIT和ROLLBACK来控制事务。COMMIT用于提交成功完成的事务,使所有更改生效;ROLLBACK则用于撤消事务,在发生错误时将表恢复到事务开始前的状态。通过设置AUTOCOMMIT变量可以进一步控制事务行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

COMMIT and ROLLBACK:
These two keywords Commit and Rollback are mainly used for MySQL Transactions.

When a successful transaction is completed, the COMMIT command should be issued so that the changes to all involved tables will take effect.

If a failure occurs, a ROLLBACK command should be issued to return every table referenced in the transaction to its previous state.

You can control the behavior of a transaction by setting session variable called AUTOCOMMIT. If AUTOCOMMIT is set to 1 (the default), then each SQL statement (within a transaction or not) is considered a complete transaction and committed by default when it finishes. When AUTOCOMMIT is set to 0, by issuing the SET AUTOCOMMIT=0 command, the subsequent series of statements acts like a transaction and no activities are committed until an explicit COMMIT statement is issued.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值