- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements