Home > Database > Mysql Tutorial > body text

What happens to the current MySQL transaction if the session ends mid-transaction?

王林
Release: 2023-08-25 09:53:04
forward
1283 people have browsed it

如果会话在事务中途结束,当前 MySQL 事务会发生什么情况?

#Assume that if the session ends in a transaction, the current MySQL transaction will be rolled back by MySQL and ended. This means that all database changes made in the current transaction will be deleted. The end of the session is called an implicit rollback.

Example

Suppose we have the following values ​​in the table "marks"

mysql> Select * from marks;
+------+---------+-----------+-------+
| Id   | Name    | Subject   | Marks |
+------+---------+-----------+-------+
| 1    | Aarav   | Maths     | 50    |
| 1    | Harshit | Maths     | 55    |
| 3    | Gaurav  | Comp      | 69    |
| 4    | Rahul   | History   | 40    |
| 5    | Yashraj | English   | 48    |
| 6    | Manak   | History   | 70    |
+------+---------+-----------+-------+
6 rows in set (0.00 sec)

mysql> START TRANSACTION;
Query OK, 0 rows affected (0.00 sec)

mysql> UPDATE marks SET Name = ‘Yash’ Where id = 5;
Query OK, 1 row affected (0.06 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> quit;
Bye
Copy after login

In the above example, after updating the values ​​in the table, end the session by running the quit statement . When we look at the table after starting the session again, the updated values ​​have been rolled back by MySQL because the session ended in a transaction.

The above is the detailed content of What happens to the current MySQL transaction if the session ends mid-transaction?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!