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

Two main methods of MYSQL transaction processing

2025-03-04 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

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

The following mainly brings you the two main methods of MYSQL transaction processing. I hope these contents can bring you practical use, which is also the main purpose of this article. All right, don't talk too much nonsense, let's just read the following.

There are three points to pay attention to when using transactions:

1. Only databases or tables that use the Innodb database engine in MySQL support transactions.

2. Transaction processing can be used to maintain the integrity of the database and ensure that batches of SQL statements are either executed or not executed.

3. Transactions are used to manage insert,update,delete statements

There are two main methods of MYSQL transaction processing:

1. Implement it with BEGIN, ROLLBACK and COMMIT.

BEGIN starts a transaction

ROLLBACK transaction rollback

COMMIT transaction confirmation

2. Directly use SET to change the automatic submission mode of MySQL:

SET AUTOCOMMIT=0 forbids automatic submission

SET AUTOCOMMIT=1 enables auto-submission

For example:

SET AUTOCOMMIT = 0 asdjoi213hjsh',' COMMIT insert INTO km_xtyh (YHID,YHMC) VALUE ('asdjoi213hjsh',' Li Si')

Interpretation:

First, auto commit is turned off, and then the transaction is opened with "BEGIN". After that, although the insert statement is used, there is no "COMMIT" operation and no real submission. The data is only temporarily stored in the database (note: at this time, there is already a "Li Si" data in the database). If the "COMMIT" statement is executed, the data will be permanently inserted into the database.

If you do not execute "COMMIT" and execute another statement "ROLLBACK", the record will not exist in the database and the data will not be inserted successfully.

For the above two main methods of MYSQL transaction processing, do you think it is very helpful? If you need to know more, please continue to follow our industry information. I'm sure you'll like it.

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

Database

Wechat

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

12
Report