Documentos de Académico
Documentos de Profesional
Documentos de Cultura
--------
Transactions Control Language(Tcl)
--------------------------------------------------------------------------------
--------
Define:
Transaction is nothing but a unit of work. We can control these transact
ions using the
following statements.
1.COMMIT Statement
2.ROLLBACK Statement
3.SAVE TRAN [SACTIONS]
1.COMMIT Statement:
This statement makes a transaction permanent. It is not possible to roll
back the committed
The COMMIT statement deletes the data from emp permanently. It is not po
ssible to ROLLBACK
the delete operation.
Example:
create table emp(sno int,ename varchar(20),address varchar(20),sal int)
insert into emp values(101,'Kannan','Erode',4000)
insert into emp values(102,'Velu','bhabani',6000)
insert into emp values(103,'Bala','Gobi',8000)
insert into emp values(104,'Kavi','Chennai',7800)
insert into emp values(105,'Sri','Trichi',4500)
select * from emp
delete * from emp
select * from emp
commit
select * from emp
or
begin tran
insert into emp values(106,'Siva','Erode',7000)
GO
update emp set sal=sal+500 where eno=101
GO
delete from emp where eno=105
Select the entire transaction and press F5 for one time
commit tran
The above COMMIT TRAN makes all three transactions permanent. We
cannot ROLLBACK
the transactions.
2.ROLLBACK Statement:
This statement is used to cancel a particular performed transaction. To
perform this statement
in Sql Server we have to follow any one of the below 2 approaches.
Approach 1: SET IMPLICIT_TRANSACTIONS ON:
This approach is only to cancel a single recently performed oper
ation.
Example:
set implicit_transactions ON
delete from emp
delete from emp
select from emp
rollback
select * from emp
select * from emp