What Is Commit And Rollback In Sql?


4 Answers

Joe McHugh Profile
Joe McHugh answered
Commit and Rollback are transaction statements that are used in database access; they can also be called Data Control Language for SQL (so you may see it as SQL DCL). A Commit statement does what it says, and commits all the changes made to data that have been made during the current transaction; a Rollback statement, again does what its name implies, and rolls back, or rescinds, all changes to the current transaction.

With reference to the changes that are made on a database, it is the SQL modification statements that should be the main consideration because they change the data. The sum total of the changes to the database because of the modification statements in a transaction are dealt with as an atomic unit. These changes are either fully persistent in the database because of the Commit statement, or have no persistent effect at all on the statement because of the Rollback statement. All changes need to be persistent or not at all; there can be no half measures.

Once the changes have been made to the data it is not possible to refer to any previous versions of it.

In the majority of instances, transactions are made by one client connection, though multiple client connections can be undertaken simultaneously. This procedure is known as concurrent transactions.

If a Commit statement does not take place at the end of a transaction and the computer crashes, then all data will be updated in its previous state. Another important point to remember is that if Commit has been written, it then becomes impossible to Rollback to the original data.

The point of Commit and Rollback is that all users of the data base will always be able to get updated information whenever it is applied.
Sriram Ganapathy Profile
Commit is to save whatever has been done. It is used to permanently store it in memory.

Roll-back is to undo something. If we use roll-back, the particular changes made are undone.
Tausif Akram Profile
Tausif Akram answered
There are various types of sql queries being used for different types of database functions. Commit is used for saving the data that has been changed permanently because whenever you perform any DML (Data Manipulation Language) like UPDATE, INSERT OR DELETE then you are required to write Commit at the end of all or every DML operation in order to save it permanently. If you do not write Commit and you program crashes then your data will be restored into its previous condition. Another key point relating to commit and DML operations is that whenever you perform DML function and then perform some DDL ( data definition language) like creating a table then the data is auto committed - no need to write explicit Commit.

Whereas if you want to restore your data into its previous condition then you can write Rollback at any time after the DML queries has been written but remember once Commit has been written then you cannot rollback the data. Moreover you can only rollback the DML queries that have been written after the last commit statement. The concept of commit and rollback is designed for data consistency because many uses manipulate data of the same table, using the same database so the user must get updated data. That is why Commit and Rollback are used.
mattleonard leonard Profile
ROLLBACK do the same finish the current transaction, but four other thing is that the changes made to database are ROLLBACK to the database.
COMMIT statement help in the completion of the transaction & make all the changes that occur in transaction persistent & this also commits all changes to the database. COMMIT can also use the store procedure.

Answer Question