Yogesh Chauhan's Blog

How to Commit and Rollback Changes in SQL?

in SQL/MySQL on January 8, 2020

Whenever we execute the INSERT, UPDATE or DELETE statements database adds them to transactions. It's like a temp file.

A transaction is a group of all those statements which need to be executed successfully before we make any changes to database.

But those changes are not permanent.

If we want to make changes to database permanent, we need to use commit and to undo all those changes we can use rollback.

Take a look at the following SQL statement.


INSERT INTO invoices VALUES (565,66, '986354', '2014-02-31', 694, 9, 6, 6, '2017-03-17', null)

//output
1 row inserted

The query above will insert a single row into invoices table. If you use SELECT after inserting the row, you will be able to see the data from the invoices table and will be able to fetch it. 

But what if someone else is using the same database?

That's why we need commit statement. It makes the changes permanent and all the user accessing the database will be able to see changes. 

The following statement will make the changes permanently after inserting those data.


COMMIT;

//output
committed

That's it.

If you want to undo the changes use the following statement:


ROLLBACK

//output
rollback complete

 


Most Read

#1 How to check if radio button is checked or not using JavaScript? #2 Solution to “TypeError: ‘x’ is not iterable” in Angular 9 #3 How to add Read More Read Less Button using JavaScript? #4 How to uninstall Cocoapods from the Mac OS? #5 PHP Login System using PDO Part 1: Create User Registration Page #6 How to Use SQL MAX() Function with Dates?

Recently Posted

#Aug 15 Is PHP still good for back-end programming? #Aug 10 How to create a multisite network in WordPress? #Aug 3 How to create a circle that follows a cursor using JavaScript and CSS? #Aug 3 How to make a curtain slider using jQuery and CSS? #Aug 2 How to progressively load images and add a blurry placeholder? #Aug 1 How to create a placeholder loader (throbber) using CSS?
You might also like these
How to change the Login Logo in WordPress?WordPressUse inline if to make a shorter conditional syntax in ReactReactThe Differences Between HAVING Clause and WHERE Clause in SQLSQL/MySQLHow Routing works in Angular?AngularWhat are Modules and Components in Angular?AngularHow to vertically align a html radio button to it’s label?CSS