The Wayback Machine - https://web.archive.org/web/20241002062428/https://www.geeksforgeeks.org/difference-between-commit-and-rollback-in-sql/
Open In App

Difference between COMMIT and ROLLBACK in SQL

Last Updated : 24 Feb, 2022
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

1. COMMIT-
COMMIT in SQL is a transaction control language that is used to permanently save the changes done in the transaction in tables/databases. The database cannot regain its previous state after its execution of commit. 

Example: Consider the following STAFF table with records: 

STAFF

sql> 
SELECT *
FROM Staff
WHERE Allowance = 400;

sql> COMMIT; 

Output: 

So, the SELECT statement produced the output consisting of three rows. 

2. ROLLBACK

ROLLBACK in SQL is a transactional control language that is used to undo the transactions that have not been saved in the database. The command is only been used to undo changes since the last COMMIT.

Example: Consider the following STAFF table with records: 

STAFF

sql> 
SELECT *
FROM EMPLOYEES
WHERE ALLOWANCE = 400;

sql> ROLLBACK; 

Output: 

So, the SELECT statement produced the same output with the ROLLBACK command. 

Difference between COMMIT and ROLLBACK 

  COMMIT ROLLBACK
1. COMMIT permanently saves the changes made by the current transaction. ROLLBACK undo the changes made by the current transaction.
2. The transaction can not undo changes after COMMIT execution. Transaction reaches its previous state after ROLLBACK.
3. When the transaction is successful, COMMIT is applied. When the transaction is aborted, incorrect execution, system failure ROLLBACK occurs.
4. COMMIT statement permanently save the state, when all the statements are executed successfully without any error.   In ROLLBACK statement if any operations fail during the completion of a transaction, it cannot permanently save the change and we can undo them using this statement.
5.

Syntax of COMMIT statement are:

COMMIT;

Syntax of ROLLBACK statement are:

ROLLBACK;



Similar Reads

What is Rollback Segment?
In this post, we will discuss the rollback segment in detail. Before the rollback segment, we need to understand transaction processing. A transaction is nothing but a logical unit of work that made changes inside the database. When a transaction execution is completed then we have two options either to make changes to the database using the commit
3 min read
Cascading Rollback
Cascading rollback is a term that is used in DBMS. It is a concept that is explained in DBMS when we start discussing transactions. So, let's discuss briefly the basics that we require to know before studying cascading rollback. What is DBMS?DBMS refers to a Database management system. We can also say that it is the manager of our databases in our
4 min read
Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
Structured Query Language (SQL): Structured Query Language (SQL) has a specific design motive for defining, accessing and changement of data. It is considered as non-procedural, In that case the important elements and its results are first specified without taking care of the how they are computed. It is implemented over the database which is drive
2 min read
Difference Between java.sql.Time, java.sql.Timestamp and java.sql.Date in Java
Across the software projects, we are using java.sql.Time, java.sql.Timestamp and java.sql.Date in many instances. Whenever the java application interacts with the database, we should use these instead of java.util.Date. The reason is JDBC i.e. java database connectivity uses these to identify SQL Date and Timestamp. Here let us see the differences
7 min read
Three Phase Commit Protocol
Three-Phase Commit (3PC) Protocol is an extension of the Two-Phase Commit (2PC) Protocol that avoids blocking problem under certain assumptions. In particular, it is assumed that no network partition occurs, and not more than k sites fail, where we assume 'k' is predetermined number. With the mentioned assumptions, protocol avoids blocking by intro
3 min read
Two Phase Commit Protocol (Distributed Transaction Management)
Consider we are given with a set of grocery stores where the head of all store wants to query about the available sanitizers inventory at all stores in order to move inventory store to store to make balance over the quantity of sanitizers inventory at all stores. The task is performed by a single transaction T that's component Tn at the nth store a
5 min read
Recovery from failures in Two Phase Commit Protocol (Distributed Transaction)
Prerequisite: Two-Phase Commit ProtocolIn the 2-phase commit protocol, the sites contributing to a distributed transaction and the coordinator that is managing the whole transaction globally may fail or crash, and this could lead to the whole transaction failure. Since unanimity is required in order to commit a distributed transaction successfully
4 min read
Commit Protocol in DBMS
This article covers topics related to the database management system. In this article, we will learn about the commit protocols that are in the subject of database management systems. This article then describes the types of Commit protocols in database management systems. It then talks about the advantages of a Database Management System. Commit P
5 min read
SQL vs NO SQL vs NEW SQL
SQL stands for Structured Query Language. Which is based on relational algebra and schema is fixed in this which means data is stored in the form of columns and tables. SQL follows ACID properties which means Atomicity, Consistency, Isolation, and Durability are maintained. There are three types of languages present in SQL : Data Definition Languag
2 min read
SQL | Difference between functions and stored procedures in PL/SQL
Prerequisite: Procedures in PL/SQLFunctions in PL/SQL.Difference between functions and stored procedures in PL/SQL Differences between Stored procedures(SP) and Functions(User-defined functions (UDF)): 1. SP may or may not return a value but UDF must return a value. The return statement of the function returns control to the calling program and ret
3 min read
Difference between T-SQL and PL-SQL
1. Transact SQL (T-SQL) : T-SQL is an abbreviation for Transact Structure Query Language. It is a product by Microsoft and is an extension of SQL Language which is used to interact with relational databases. It is considered to perform best with Microsoft SQL servers. T-SQL statements are used to perform the transactions to the databases. T-SQL has
3 min read
Difference Between Azure SQL Database and Azure SQL Managed Instances
Azure is a cloud platform which is used for services like virtual computing, storage networking etc. It provides with solutions that include Infrastructure as a Service (IaaS), Platform as a Service (PaaS), and Software as a Service (SaaS). Both, Azure SQL Database and Azure SQL Managed Instances supports automatic backup and have built-in license
3 min read
Difference between SQL and T-SQL
SQL (Structured Query Language) is the standard language for managing and manipulating relational databases, enabling operations like querying, updating, and deleting data. T-SQL (Transact-SQL), an extension of SQL developed by Microsoft, adds advanced features and procedural capabilities specifically for SQL Server. In this article, We will learn
4 min read
BULK INSERT in SQL Server(T-SQL command)
BULK INSERT in SQL Server(T-SQL command): In this article, we will cover bulk insert data from csv file using the T-SQL command in the SQL server and the way it is more useful and more convenient to perform such kind of operations. Let's discuss it one by one.  ConditionSometimes there is a scenario when we have to perform bulk insert data from .cs
3 min read
Difference between Static and Dynamic SQL
Static or Embedded SQL are SQL statements in an application that do not change at runtime and, therefore, can be hard-coded into the application. Dynamic SQL is SQL statements that are constructed at runtime; for example, the application may allow users to enter their own queries. Dynamic SQL is a programming technique that enables you to build SQL
2 min read
Difference between Simple and Complex View in SQL
A View in SQL as a logical subset of data from one or more tables. Views are used to restrict data access. A View contains no data of its own but it is like a window through which data from tables can be viewed or changed. The table on which a View is based is called BASE Tables. There are 2 types of Views in SQL: Simple View and Complex View. Simp
2 min read
Difference between SQL and PLSQL
Introduction SQL: Structured Query Language (SQL) is a standard Database language that is used to create, maintain and retrieve the relational database. The advantages of SQL are: SQL could be a high-level language that has a larger degree of abstraction than procedural languages.It enables the systems personnel end-users to deal with several datab
3 min read
Difference between MySQL and MS SQL Server
SQL is an acronym for Structured Query Language. It is used to access, manipulate and retrieve information from a database. MySQL is an open source Relational Database Management System (RDBMS) based on Structured Query Language (SQL). It runs on platforms like Linux, UNIX and Windows. SQL Server is owned and developed by Microsoft Corporation. The
2 min read
Difference between JOIN and UNION in SQL
Pre-requisites: JOIN, UNION JOIN in SQL is used to combine data from many tables based on a matched condition between them. The data combined using the JOIN statement results in new columns. Consider the two tables: Boys Girls Example: sql> SELECT Boys.Name, Boys.Age, Girls.Address, FROM Boys INNER JOIN Girls ON Boys.Rollno = Girls.Rollno; The r
2 min read
Difference Between Hadoop and SQL Performance
Hadoop: Hadoop is an open-source software framework written in Java for storing data and processing large datasets ranging in size from gigabytes to petabytes. Hadoop is a distributed file system that can store and process a massive amount of data clusters across computers. Hadoop from being open source is compatible with all the platforms since it
4 min read
Difference between From and Where Clause in SQL
1. FROM Clause: It is used to select the dataset which will be manipulated using Select, Update or Delete command.It is used in conjunction with SQL statements to manipulate dataset from source table.We can use subqueries in FROM clause to retrieve dataset from table. Syntax of FROM clause: SELECT * FROM TABLE_NAME; 2. WHERE Clause: It is used to a
2 min read
Difference Between Hadoop and SQL
Hadoop: It is a framework that stores Big Data in distributed systems and then processes it parallelly. Four main components of Hadoop are Hadoop Distributed File System(HDFS), Yarn, MapReduce, and libraries. It involves not only large data but a mixture of structured, semi-structured, and unstructured information. Amazon, IBM, Microsoft, Cloudera,
3 min read
Difference between Natural join and Inner Join in SQL
The join operation merges the two tables based on the same attribute name and their datatypes are known as Natural join Unlike INNER JOIN, which requires you to specify the columns and conditions for the join explicitly. In this article, we will also see the differences between them. Let's start with Natural Join. Example: If you have two tables "S
3 min read
Difference between Natural join and Cross join in SQL
1. Natural Join : Natural Join joins two tables based on same attribute name and datatypes. The resulting table will contain all the attributes of both the tables but only one copy of each common column. Example: Consider the two tables given below: Student Table Marks Table Consider the given query SELECT * FROM Student S NATURAL JOIN Marks M; Out
2 min read
Difference between MariaDB and MS SQL Server
1. MariaDB : MariaDB is an open source relational database management system (RDBMS) that is a compatible drop-in replacement for the widely used MySQL database technology. It is developed by MariaDB Foundation and initially released on 29 October 2009. MariaDB has a significantly high number of new features, which makes it better in terms of perfo
2 min read
Difference between SQL and HiveQL
1. Structured Query Language (SQL): SQL is a domain-specific language used in programming and designed for managing data held in a relational database management system also known as RDBMS. It is also useful in handling structured data, i.e., data incorporating relations among entities and variables. SQL is a standard language for storing, manipula
2 min read
Difference between ALTER and UPDATE Command in SQL
1. ALTER Command: ALTER SQL command is a DDL (Data Definition Language) statement. ALTER is used to update the structure of the table in the database (like add, delete, modify the attributes of the tables in the database). Syntax: // add a column to the existing table ALTER TABLE tableName ADD columnName columnDefinition; // drop a column from the
3 min read
Difference between MS SQL Server and MongoDB
1. MS SQL Server : Microsoft SQL Server is a relational database management system (RDBMS) that is platform dependent and it is both GUI and command based software. It supports a wide variety of transaction processing, business intelligence, and analytics applications in corporate IT environments. It was developed by Microsoft Corporation and initi
2 min read
Difference between MS SQL Server and Cassandra
1. MS SQL Server : Microsoft SQL Server is a relational database management system (RDBMS) which is platform dependent and it is both GUI and command based software. It supports a wide variety of transaction processing, business intelligence, and analytics applications in corporate IT environments. It was developed by Microsoft Corporation and init
2 min read
Difference between Couchbase and MS SQL Server
1. Couchbase : Couchbase Server is an open-source, distributed multi-model NoSQL document-oriented database software package that is optimized for interactive applications. It is also known as Membase. It was developed by Couchbase, Inc. and initially released on August 2010. 2. MS SQL Server : Microsoft SQL Server is a relational database manageme
2 min read