Home >Database >Mysql Tutorial >How can we perform START transaction in MySQL stored procedure?

How can we perform START transaction in MySQL stored procedure?

王林
王林forward
2023-08-23 16:55:36966browse

我们如何在 MySQL 存储过程中执行 START 事务?

# As we know, START transaction will start the transaction and set the auto-commit mode to off. In the example below, we have created a stored procedure with a START transaction that will insert a new record in the employee.tbl table with the following data:

mysql> Select * from employee.tbl;
+----+---------+
| Id | Name    |
+----+---------+
| 1  | Mohan   |
| 2  | Gaurav  |
| 3  | Rahul   |
+----+---------+
3 rows in set (0.00 sec)

Example

mysql> Delimiter //
mysql> Create Procedure st_transaction()
   -> BEGIN
   -> START TRANSACTION;
   -> INSERT INTO employee.tbl(name) values ('Saurabh');
   -> END //
Query OK, 0 rows affected (0.00 sec)

Now when we call this procedure it will insert the values ​​into the table employee.tbl.

mysql> Delimiter ;
mysql> Call st_transaction();
Query OK, 0 rows affected (0.17 sec)

mysql> Select * from employee.tbl;
+----+---------+
| Id | Name    |
+----+---------+
|  1 | Mohan   |
|  2 | Gaurav  |
|  3 | Rahul   |
|  4 | Saurabh |
+----+---------+
4 rows in set (0.00 sec)

The above is the detailed content of How can we perform START transaction in MySQL stored procedure?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete