---
title: "Transaction in SQL Server"  
description: "In .NET environment we can define transaction boundary by Transaction object. 1. If you are using SqlClient (namespace System.Data.SqlClient) Managed"  
author: "AVADHESH PATEL"  
published: 2012-08-25  
updated: 2014-09-18  
canonical: https://www.mindstick.com/blog/348/transaction-in-sql-server  
category: "database"  
tags: ["database"]  
reading_time: 2 minutes  

---

# Transaction in SQL Server

In .NET [environment](https://yourviews.mindstick.com/view/308/need-to-create-a-supportive-work-environment-for-women) we can define [transaction](https://www.mindstick.com/blog/175/transactions-in-database) boundary by Transaction object.

1. If you are using SqlClient (namespace System.Data.SqlClient) Managed Provider you can SqlTransaction object. \
2. If you are using Oledb (namespace System.Data.Oledb) Managed Provider you can OledbTransaction object. \
3. If you are using Odbc (namespace Microsoft.Data.Odbc) Managed Provider you can OdbcTransaction object \

##### A transaction must follows this properties:-

\
In a perfect transaction world, a transaction must contain a series of properties [known as](https://answers.mindstick.com/qa/35703/ricky-ponting-is-also-known-as-what) ACID. These properties are:

##### Atomicity

A transaction is an atomic [unit of work](https://www.mindstick.com/articles/13071/generic-repository-pattern-with-unit-of-work-uow) or collection of separate operations. So, a transaction succeeds and is committed to the database only when all the separate operations succeed. On the other hand, if any single operations fail during the transaction, everything will be [considered as](https://www.mindstick.com/forum/156093/what-is-considered-as-more-significant-creating-content-or-building-backlinks) failed and must be rolled back if it is already [taken place](https://answers.mindstick.com/qa/38823/the-indigo-revolt-taken-place-in). Thus, Atomicity helps to avoid data inconsistencies in database by eliminating the chance of processing a part of operations only. \

##### Consistency

A transaction must leave the database into a consistent state whether or not it is completed successfully. The data modified by the transaction must comply with all the [constraints](https://www.mindstick.com/forum/34816/what-is-mapping-constraints-in-database-management-system) in order to maintain integrity. \
\

##### Isolation

Every transaction has a well defined boundary. One transaction will never affect another transaction running at the same time. Data modifications made by one transaction must be isolated from the data modification made by all other transactions. A transaction sees data in the [state as](https://answers.mindstick.com/qa/38051/what-is-the-meaning-of-foreign-state-as-given-in-our-indian-constitution) it was before the second transaction modification [takes place](https://yourviews.mindstick.com/view/81718/pranab-mukherjee-death-how-last-rites-of-former-president-of-india-takes-place) or in the state as the second transaction completed, but under any circumstance a transaction cannot be in any intermediate state. \
\

##### Durability

If a transaction succeeds, the updates are stored in permanent media even if the database crashes immediately after the [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) performs a commit operation. Transaction logs are maintained so that the database can be restored to its original position before failure takes place.

---

Original Source: https://www.mindstick.com/blog/348/transaction-in-sql-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
