Monday, August 13, 2007

FAQ on Transaction in SQL Server

FAQ on Transaction in SQL Server

84. What is Transaction?
A transaction is a sequence of operations performed as a single
logical unit of work. A logical unit of work must exhibit four
properties, called the ACID (Atomicity, Consistency, Isolation, and
Durability) properties, to qualify as a transaction:
• Atomicity - A transaction must be an atomic unit of work; either all
of its data modifications are performed or none of them is performed.
• Consistency - When completed, a transaction must leave all data in a
consistent state. In a relational database, all rules must be applied
to the transaction's modifications to maintain all data integrity. All
internal data structures, such as B-tree indexes or doubly-linked
lists, must be correct at the end of the transaction.
• Isolation - Modifications made by concurrent transactions must be
isolated from the modifications made by any other concurrent
transactions. A transaction either sees data in the state it was in
before another concurrent transaction modified it, or it sees the data
after the second transaction has completed, but it does not see an
intermediate state. This is referred to as serializability because it
results in the ability to reload the starting data and replay a series
of transactions to end up with the data in the same state it was in
after the original transactions were performed.
• Durability - After a transaction has completed, its effects are
permanently in place in the system. The modifications persist even in
the event of a system failure.

85. After one Begin Transaction a truncate statement and a RollBack
statements are there. Will it be rollbacked? Since the truncate
statement does not perform logged operation how does it RollBack?
It will rollback.

86. Given a SQL like
Begin Tran
Select @@Rowcount
Begin Tran
Select @@Rowcount
Begin Tran
Select @@Rowcount
Commit Tran
Select @@Rowcount
Select @@Rowcount
Select @@Rowcount
What is the value of @@Rowcount at each stmt levels?
Ans : 0 – zero.
@@ROWCOUNT - Returns the number of rows affected by the last statement.
@@TRANCOUNT - Returns the number of active transactions for the
current connection.
Each Begin Tran will add count, each commit will reduce count and ONE
rollback will make it 0.

For More SQL SERVER Frequently Asked Interview Questions

No comments:

Most Recent Post

Community Updates

Subscribe Blog via Email

Enter your email address:

Disclaimers:We have tried hard to provide accurate information, as a user, you agree that you bear sole responsibility for your own decisions to use any programs, documents, source code, tips, articles or any other information provided on this Blog.
Page copy protected against web site content infringement by Copyscape