
- 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
Which statement, other than START TRANSACTION, is used for starting a 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)
In this example, the transaction is initiated by the BEGIN Statement rather than START TRANSACTION statement. Two INSERT statements are then executed followed by a ROLLBACK statement. 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 have been 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)
- Related Articles
- What will happen to the current MySQL transaction if a START TRANSACTION command is executed in the middle of that current transaction?
- How to start a transaction in JDBC?
- How can a user start new MySQL transaction?
- What will happen to MySQL current transaction, if in the middle of that transaction, the DDL statement is executed?
- What is a shielded transaction?
- Differentiate between cash transaction and credit transaction
- What is transaction processing? Explain the properties of the transaction(DBMS)
- What happens when we use COMMIT in MySQL stored procedure and one of the transaction, under START transaction, fails?
- MongoDB transaction & indexes for duplicate values
- What is dirty read in a transaction(DBMS)?
- What happens to the current MySQL transaction if the session is ended in the middle of a transaction?
- Transaction lock in MongoDB?
- Identify required fields for an MB01 transaction in SAP
- Checking transaction list waiting for lock-in SAP HANA
- Definition of Transaction in Database

Advertisements