Professional Documents
Culture Documents
Difference Between COMMIT and ROLLBACK in SQL: Databases
Difference Between COMMIT and ROLLBACK in SQL: Databases
databases.
COMMIT in SQL is a transaction control language which is used to permanently save the
changes done in the transaction in tables/databases. The database cannot regain its
previous state after the execution of it.
Consider the following STAFF table with records:
STAFF
Example:
sql>
SELECT *
FROM Staff
WHERE Allowance = 400;
sql> COMMIT;
Output:
So, the SELECT statement produced the output consisting of three rows.
2. ROLLBACK:
Example:
sql>
SELECT *
FROM EMPLOYEES
WHERE ALLOWANCE = 400;
sql> ROLLBACK;
Output:
So, the SELECT statement produced the same output with ROLLBACK command.
Difference between COMMIT and ROLLBACK:
COMMIT ROLLBACK
COMMIT permanently saves the changes made by ROLLBACK undo the changes made by
current transaction. current transaction.
Transaction can not undo changes after COMMIT Transaction reaches its previous state after
execution. ROLLBACK.
SQL Constraints
SQL constraints are used to specify rules for the data in a table.
Constraints are used to limit the type of data that can go into a table. This
ensures the accuracy and reliability of the data in the table. If there is any
violation between the constraint and the data action, the action is aborted.
Constraints can be column level or table level. Column level constraints apply to
a column, and table level constraints apply to the whole table.