Home > Database > Mysql Tutorial > Besides START TRANSACTION, which statement is used to start a transaction?

Besides START TRANSACTION, which statement is used to start a transaction?

王林
Release: 2023-08-26 16:45:03
forward
1388 people have browsed it

除了 START TRANSACTION 之外,哪个语句用于启动事务?

We can also use the BEGIN statement to start a new transaction. It is the same as the START TRANSACTION statement.

Example

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

mysql> INSERT INTO Marks Values(1, 'Aarav','History',40);
Query OK, 1 row affected (0.00 sec)

mysql> INSERT INTO Marks Values(2, 'Harshit','History',48);
Query OK, 1 row affected (0.00 sec)

mysql> ROLLBACK;
Query OK, 0 rows affected (0.04 sec)
Copy after login

In this example, the transaction is started by the BEGIN statement instead of the START TRANSACTION statement. Then execute two INSERT statements, followed by a ROLLBACK statement. The ROLLBACK statement will undo the changes made to the database, which can be observed from the following result set, which shows that no new values ​​were inserted into the table -

mysql> SELECT * FROM Marks;
+------+---------+---------+-------+
| Id   | Name    | Subject | Marks |
+------+---------+---------+-------+
|    1 | Aarav   | Maths   |    50 |
|    2 | Harshit | Maths   |    55 |
+------+---------+---------+-------+
2 rows in set (0.00 sec)
Copy after login

The above is the detailed content of Besides START TRANSACTION, which statement is used to start a 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