Use of Begin, Commit, Rollback Transactions in SQL Server

No.of Views1664
Bookmarked1 times
Downloads 
Votes0
By  youngmurukan   On  31 May 2010 23:05:40
Tag : Sql Servers , Database Administrator
The SQL Server provides very useful feature which is Begin, Commit, Rollback Transaction.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

The SQL Server provides very useful feature which is Begin, Commit, Rollback Transaction.


When we use Begin Transaction before we use DML Queries, we can Commit or Rollback that Transaction after the confirmation. This is very useful if you update anything wrongly then you can rollback that transaction.For example,As shown below, I am trying to update the NodeID column data to 5 from 1.  

Image Loading
begin transactionupdate DownLoad_Data set NodeID=5

But after I updated, You can check whether you have been updated properly. But here, I realised I did not mention the Where clause. 

select * from DownLoad_Data
Image Loading

So I have to rollback this transaction. For that I can use Rollback Transaction since I used Begin Transaction.

 

Rollback transaction

So again I changed the Query and run it.

 

Begin transactionupdate DownLoad_Data set NodeID=5 where RecNo=1

Still you can check whether have been updated properly. If it is updated correctly then, Run the Commit Transaction to make all updates permanently.

 

Image Loading
Commit Transaction

I hope this would have been very useful for you all.

 
Sign Up to vote for this article
 
About Author
 
youngmurukan
Occupation-Not Provided
Company-Not Provided
Member Type-Senior
Location-Not Provided
Joined date-12 May 2009
Home Page-Not Provided
Blog Page-Not Provided
 
 
Other popularSectionarticles
Comments
There is no comments for this articles.
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top