Monday, March 19, 2012

Is this a 'dirty read'?

Hello,

trying to understand the concepts of isolation levels not understanding it completely this is my question:

Client A and client B both are querying the same database.
Situation:
- client B starts a transactional operation
- client A executes a non-transactional read operation
- client B rolls back his transactional operation

Is the non-transactional read operation executed by client A called
a 'dirty read'? Or do isolation levels always apply to at least two
clients executing BOTH transactional operations?

regards,
HenkProbably not...depending on if you are using the READUNCOMMITTED isolation level. A dirty read occurs when transactionA starts, updates data, and TransactionB issues a read against a what transactionA is modifiying and transactionB does not issue shared locks against that table when reading it. If transA rolls it work back, transB has read dirty data. Here is an example:

TransA:
BEGIN TRAN
INSERT INTO TableA VALUES('A')

TransB:
SELECT * FROM TableA WITH(NOLOCK)

TransA:
ROLLBACK TRAN

TransB will have read the row that was rolled back from the database, and thus a dirty read.

Hope this helps,
Tim

No comments:

Post a Comment