Home > Database > Mysql Tutorial > body text

What happens if a DDL statement is executed in the middle of the current MySQL transaction?

王林
Release: 2023-08-23 17:05:02
forward
795 people have browsed it

What happens if a DDL statement is executed in the middle of the current MySQL transaction?

When any DDL statement (such as CREATE or DROP database, CREATE, ALTER or DROP table or stored procedure) is executed in the current transaction, the current MySQL transaction will be committed and ended . All database changes made within the current transaction become permanent and cannot be rolled back.

Example

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

mysql> INSERT INTO MARKS Values(6,'Manak','History',70);
Query OK, 1 row affected (0.26 sec)

mysql> Create table student(id int, Name Varchar(10),);
Query OK, 0 rows affected (0.84 sec)
Copy after login

As we can see in the above example, a DDL statement is executed in the middle of a transaction, so this transaction will end implicitly. MySQL will save all changes and cannot roll back. We can observe this through the following result set:

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

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)
Copy after login

The above is the detailed content of What happens if a DDL statement is executed in the middle of the current MySQL 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!