You are on page 1of 3

SQL is a standard language for storing, manipulating and retrieving data in

databases.

SQL stands for Structured Query Language

Difference between COMMIT and ROLLBACK in SQL

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:

ROLLBACK in SQL is a transactional control language which is used to undo the


transactions that have not been saved in database. The command is only be used to undo
changes since the last COMMIT.
Consider the following STAFF table with records:
STAFF

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.

When transaction is successful, COMMIT is When transaction is aborted, ROLLBACK


applied. occurs.

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.

The following constraints are commonly used in SQL:

 NOT NULL - Ensures that a column cannot have a NULL value


 UNIQUE - Ensures that all values in a column are different
 PRIMARY KEY - A combination of a NOT NULL and UNIQUE. Uniquely identifies
each row in a table
 FOREIGN KEY - Prevents actions that would destroy links between tables
 CHECK - Ensures that the values in a column satisfies a specific condition
 DEFAULT - Sets a default value for a column if no value is specified
 CREATE INDEX - Used to create and retrieve data from the database very
quickly

c/o I d shrmveer Sec-18

You might also like