
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we perform START transactions inside MySQL stored procedure?
As we know the START transaction will start the transaction and set the auto-commit mode to off. In the following example, we have created a stored procedure with a START transaction which will insert a new record in table employee.tbl having 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 invoke this procedure, it will insert the value in 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)
- Related Articles
- How can we perform COMMIT transactions inside MySQL stored procedure?
- How can we perform ROLLBACK transactions inside a MySQL stored procedure?
- How can we handle a result set inside MySQL stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- How can we invoke MySQL stored procedure?
- How can we alter a MySQL stored procedure?
- How can we drop a MySQL stored procedure?
- What is stored procedure and how can we create MySQL stored procedures?
- How can we write MySQL handler in a stored procedure?
- How can we create MySQL stored procedure to calculate the factorial?
- Perform mathematical operations in a MySQL Stored Procedure?
- How can we use nested transactions in MySQL?
- Implement Dynamic SQL query inside a MySQL stored procedure?
- How can we see the source code of a particular MySQL stored procedure?
- How can we use nested transactions allowed in MySQL?

Advertisements