Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Three minutes to master the handling of transactions in MySQL

2025-01-22 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the handling of transactions in MySQL, the contents of the articles are carefully selected and edited by the author, with a certain pertinence, the reference significance for everyone is still relatively great, the following with the author to understand the handling of transactions in MySQL.

Steps:

1. Open transaction start transaction

When we start a transaction, our operations on sql take place in memory, but there is no real feedback to the file on the database disk!

two。 Roll back rollback

Rollback is to return to the original state before the transaction starts!

Note: the rollback operation will automatically close a transaction. If you want to execute the transaction again, you need to reopen the transaction!

3. Submit commit

The basic principles of transactions

Ordinary execution is executed immediately and takes effect, because by default, MySQL's execution of sql statements is automatically committed! Therefore, the essence of opening a transaction is to turn off the previous auto-commit function, but by the user to manually commit (using the commit statement)!

Steps to summarize the transaction:

1. Start the transaction

2. If the execution is successful, submit the commit.

3. If any of the sql statements fail, roll back rollback!

The most typical transaction is borrowing and repaying money. Let's take Zhang San returning 1000 yuan to Li Si as an example.

First check the respective amount of money in the database

Here is the code to handle the repayment transaction:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report