0% found this document useful (0 votes)
81 views3 pages

Chapter 5 COMMIT and ROLLBACK TCL

The document discusses transaction control statements in Oracle such as COMMIT, ROLLBACK, and SAVEPOINT. COMMIT makes changes to the database permanent, ROLLBACK undoes changes to the last commit point, and SAVEPOINT allows rolling back to a specified point in the transaction. Examples demonstrate using each statement to commit inserted rows, rollback deleted rows, and rollback to a savepoint while retaining some changes.

Uploaded by

Ali Sheikh Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views3 pages

Chapter 5 COMMIT and ROLLBACK TCL

The document discusses transaction control statements in Oracle such as COMMIT, ROLLBACK, and SAVEPOINT. COMMIT makes changes to the database permanent, ROLLBACK undoes changes to the last commit point, and SAVEPOINT allows rolling back to a specified point in the transaction. Examples demonstrate using each statement to commit inserted rows, rollback deleted rows, and rollback to a savepoint while retaining some changes.

Uploaded by

Ali Sheikh Ahmed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

COMMIT and ROLLBACK

Transaction Control Language (TCL)


Transaction control statements manage changes made by DML statements.

What is a Transaction?
A transaction is a set of SQL statements which Oracle treats as a Single Unit. i.e. all the statements
should execute successfully or none of the statements should execute.

To control transactions Oracle does not made permanent any DML statements unless you commit it.
If you don’t commit the transaction and power goes off or system crashes then the transaction is roll
backed.

TCL Statements available in Oracle are

COMMIT       :    Make changes done in  transaction permanent.


ROLLBACK  :    Rollbacks the state of database to the last commit point.
SAVEPOINT :    Use to specify a point in transaction to which later you can rollback.

COMMIT
To make the changes done in a transaction permanent issue the COMMIT statement.

The syntax of COMMIT Statement is

COMMIT  [WORK]  [COMMENT ‘your comment’];

WORK is optional.

COMMENT is also optional, specify this if you want to identify this transaction in data dictionary
DBA_2PC_PENDING.

Example

insert into emp (empno,ename,sal) values (101,’Abid’,2300);

commit;

 
ROLLBACK
To rollback the changes done in a transaction give rollback statement. Rollback restore the state of
the database to the last commit point.

Example :

delete from emp;

rollback;          /* undo the changes */

SAVEPOINT
Specify a point in a transaction to which later you can roll back.

Example

insert into emp (empno,ename,sal) values (109,’Sami’,3000);


savepoint a;
insert into dept values (10,’Sales’,’Hyd’);
savepoint b;
insert into salgrade values (‘III’,9000,12000);

Now if you give

rollback to a;

Then  row from salgrade table and dept will be roll backed. At this point you can commit the row
inserted into emp table or rollback the transaction.

If you give

rollback to b;

Then row inserted into salgrade table will be roll backed. At this point you can commit the row
inserted into dept table and emp table or rollback to savepoint a or completely roll backed the
transaction.

If you give

rollback;

Then the whole transactions is roll backed.


If you give

commit;

Then the whole transaction is committed and all savepoints are removed.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy