Articles → SQL SERVER → Transactions in SQL server

Transactions in SQL server






What are transactions?







Syntax


Begin Transaction

-- commit command will make the changes permanent in database
Commit Transaction

-- rollback command will cancel the whole transaction
RollBack TRANSACTION



Example





Click to Enlarge



Begin Transaction

Insert Into T1 values('Test1')
Insert Into T2 values('Test1')

Commit Transaction

IF @@ERROR > 0

RollBack TRANSACTION







Click to Enlarge



Begin Transaction

Insert Into T1 values('Test2')
Insert Into T2 values('Test2')

Commit Transaction

IF @@ERROR > 0

RollBack TRANSACTION





Click to Enlarge




Click to Enlarge


Posted By  -  Karan Gupta
 
Posted On  -  Tuesday, September 12, 2017

Query/Feedback


Your Email Id  
 
Subject 
 
Query/FeedbackCharacters remaining 250