如果在当前事务中间执行 START TRANSACTION,则当前事务将被提交并结束。当前事务中所做的所有数据库更改都将永久生效。这称为 START TRANSACTION 命令的隐式提交。
示例
假设我们在表“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)
在此示例中,我们可以观察到,当在当前事务中间执行 START TRANSACTION 语句时,它将隐式结束当前事务并提交更改。
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)