If START TRANSACTION is executed in the middle of the current transaction, the current transaction will be committed and ended. All database changes made during the current transaction are made permanent. This is called an implicit commit of the START TRANSACTION command.
Suppose we have the following values in table "marks"
mysql> select * from marks; +------+---------+-----------+-------+ | Id | Name | Subject | Marks | +------+---------+-----------+-------+ | 1 | Aarav | Maths | 50 | | 1 | Harshit | Maths | 55 | | 3 | Gaurav | Comp | 69 | +------+---------+-----------+-------+ 3 rows in set (0.00 sec) mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec) mysql> INSERT INTO Marks Values(4, 'Rahul','History',40); Query OK, 1 row affected (0.00 sec) mysql> INSERT INTO Marks Values(5, 'Yashraj','English',48); Query OK, 1 row affected (0.00 sec) mysql> START TRANSACTION; Query OK, 0 rows affected (0.00 sec)
In this example, we can observe that when the START TRANSACTION statement is executed in the middle of the current transaction , it will implicitly end the current transaction and commit the changes.
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 | +------+---------+-----------+-------+ 5 rows in set (0.00 sec)
The above is the detailed content of What happens to the current MySQL transaction if a START TRANSACTION command is executed in the middle of the current transaction?. For more information, please follow other related articles on the PHP Chinese website!