Sei sulla pagina 1di 2

Commit, Rollback and Savepoint SQL commands

Transaction Control Language(TCL) commands are used to manage transactions in the


database.
These are used to manage the changes made to the data in a table by DML statements.

COMMIT command
COMMIT command is used to permanently save any transaction into the database.

OR

On execution of this command all changes to the database made by you are made
permanent and cannot be undone.

NOTE:A COMMIT does not apply to any DDL commands (eg CREATE TABLE, CREATE INDEX,
etc). These are automatically committed and cannot be rolled back.

If you wished to rollback (ie undo) any changes made to the database since the last
commit, you can issue the command:

ROLLBACK;

EXAMPLE
https://www.allinterview.com/showanswers/66308/what-is-difference-between-commit-
and-rollback.html

suppose u have one table which is in database. The table


contains some records. U want to modify one record of table.
after modification, u don't want that new values for
the record. just u use rollback command. previous values are
placed in database.

Example:
Case 1: Roll Back
sno name palce
1 abc hyderabad
2 xyz bangalore.

This is the table and it contains some records.


Suppose if u want change the 2nd record, means palce
is changed to chennai.

After modification:
sno name palce
1 abc hyderabad
2 xyz Chennai.

Suppose if u want old values, means u don't want new


values. At that time u use roll back command

After useing rollback:


sno name palce
1 abc hyderabad
2 xyz bangalore.
after using roll back, the records are comes like
above(original records)

Case 2: Commit
sno name palce
1 abc hyderabad
2 xyz bangalore.

This is the table and it contains some records.


Suppose if u want change the 2nd record, means palce
is changed to chennai.

After modification:
sno name palce
1 abc hyderabad
2 xyz Chennai.

After useing commit:


sno name palce
1 abc hyderabad
2 xyz Chennai.
after using commit, the table is finilased.u can't get
old values by uisng roll back.

Once if u use commit,u can't get old values for using of


rollback. Before commit, u can get old values for rollback.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

Commit mean if change the values after commit u cont replace


old values.

Rollback mean if u r not given commit u will get previous


values.

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@

* COMMIT is used to save the changes permanantly on the server

* ROLLBACK is used to undo the changes and restore previous state.

DROP & TRUNCATE can't be rolled back

Potrebbero piacerti anche