|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:11 PM
Points: 3,390,
Visits: 3,403
|
|
I chose the correct answer because I felt it was most correct. But the way I read it was that if you had READ_COMMITTED_SNAPSHOT set to on, it would produce the same result? But that is not the case?
From BOL: If READ_COMMITTED_SNAPSHOT is set to ON, the Database Engine uses row versioning to present each statement with a transactionally consistent snapshot of the data as it existed at the start of the statement. Locks are not used to protect the data from updates by other transactions.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, June 08, 2012 7:51 AM
Points: 1,219,
Visits: 225
|
|
Cliff, You are right that READ_COMMITTED_SNAPSHOT being on or off changes outcomes, but just not in the case stated, because of the WAY it is stated. As long as the two overlapping transactions do not commit and also do not end, they will see the original data row values unless they change the values within themselves, a la Transaction 2. The READ_COMMITTED_SNAPSHOT only makes a difference if there is an intervening commit.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:11 PM
Points: 3,390,
Visits: 3,403
|
|
| Wouldn't the last select hang waiting for the pending commit or rollback?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, June 08, 2012 7:51 AM
Points: 1,219,
Visits: 225
|
|
| No. Only if there was a commit and then it go locked by another transaction. Within a transaction, changes made but not committed are immediately available. The changed row is not locked by the transaction that made the change when it is referencing within itself. The uncommitted row is only unavailable and invisible to other transactions.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:11 PM
Points: 3,390,
Visits: 3,403
|
|
| Does it work this way because the original select and final select are within a transaction? Or does that matter?
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Friday, June 08, 2012 7:51 AM
Points: 1,219,
Visits: 225
|
|
| Yes, that is exactly why. As I said, the issue of the correct answer relates to the specific phrasing and setup of the scenario. If there were either commits or transaction ends between the queries and updates, the result would be very much influenced by the high order database setting of READ_COMMITTED_SNAPSHOT.
|
|
|
|
|
Hall of Fame
       
Group: General Forum Members
Last Login: Tuesday, May 14, 2013 4:11 PM
Points: 3,390,
Visits: 3,403
|
|
| Got it. Thanks for the clarification.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:04 AM
Points: 1,342,
Visits: 1,946
|
|
Bitbucket,
Irish Flyer has already stated the fact that was confusing me.
From the way your scenario was stated, the second script did not commit its changes. Hence I wrote my tests using 'ROLLBACK TRAN' to cancel the commits.
As a result, I can't see any way to distinguish between READ COMMITTED and SNAPSHOT (as my tests showed) in the given scenario.
They are only distinguishable if something actually gets commited.
If script 2 actually commited it's change before script 1's second select and script 1 got the same result then that would be SNAPSHOT, but since that's not how you stated the problem I don't see how you can choose between the two.
Derek
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: 2 days ago @ 8:17 AM
Points: 334,
Visits: 280
|
|
| I agree with BitBucket. The results described at what you would expect in "normal" operations (assuming the typo is corrected)
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:04 AM
Points: 1,342,
Visits: 1,946
|
|
Ray Herring (3/6/2009) I agree with BitBucket. The results described at what you would expect in "normal" operations (assuming the typo is corrected)I understand the sections BitBucket quoted, but can't see how the answer SNAPSHOT is correct and READ COMMITTED isn't when the scenario has no commits!
As far I can see, since nothing has been committed, it doesn't matter which isolation level is in effect, transaction 1 won't see any change.
Now if the scenario was changed so that transaction 2 committed it's change before 1's 2nd select then the described behaviour is SNAPSHOT isolation level. But the question explicitly stated
The first transaction continues and again executes before the 2nd transaction committs
In this situation, it's impossible to tell whether it's SNAPSHOT or READ COMMITTED, as my test scripts show!
Derek
|
|
|
|