Wednesday 12 March 2014

Transactions in SQL Server 2012

 

Well i am learning transaction these days, So thought of sharing my earnings with all. well this is very useful when we need to have good control on transaction. Or in case of failure/error we can handle the transaction like roll back the changes . During learning process i referred couple of blogs and MSDN as well.

Transactions:

Basically as simple it is, transaction is any task performed in SQL Server by our command given. To be precise smallest unit of task called transaction. For example, reading data from table, inserting data to the table we say its transaction.

When we use select statement, we read data. It’s transaction. We update table, again we enter data to the specified table its transaction. Similarly we give any command from SSMS, read data or write information to memory/Table.

Transactions are having standard property called ACID:

  • Atomicity: Guaranty the task, for its success or failure.
  • Consistent: Ensures that the database properly changes states upon a successfully committed transaction.
  • Isolation: Ensures that the database properly changes states upon a successfully committed transaction.
  • Durability: Ensures that the result or effect of a committed transaction persists in case of a system failure.

Sometimes we need to control over the transactions we made, thus SQL provides some commands to us, to control the transaction for DML (Select, Insert and Update). These commands are:

  • Begin Transaction
  • Commit Transaction
  • Rollback Transaction
  • Save Transaction

 

This becomes Important to talk about Global Variable @@TRANCOUNT when we are discussing about Transactions. This is the variable which keeps the value ,or number of times Transaction happened which is not yet committed. If there is no Transaction then value in this variable would be zero.

We can discuss about this in Next blog.

No comments:

Post a Comment