17.07.2015 Views

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

Defensive Database Programming - Red Gate Software

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Chapter 4: When Upgrading Breaks CodeSELECT ID ,CommentFROM dbo.TestTable ;--COMMIT ;Beginning transactionIDComment----------- ----------------------------------------1 Row committed before transaction began(1 row(s) affected)Listing 4-5: Tab 2, when using SNAPSHOT isolation, the same query completes.The same query under READ_COMMITTED_SNAPSHOT also completes, and the output isexactly the same as in the previous listing. Open a new tab and run the script shown inListing 4-6.IF @@TRANCOUNT = 0BEGIN ;-- this is actually READ_COMMITTED_SNAPSHOT because-- we have already set READ_COMMITTED_SNAPSHOT to ONSET TRANSACTION ISOLATION LEVEL READ COMMITTED ;PRINT 'Beginning transaction' ;BEGIN TRANSACTION ;END ;SELECT ID ,CommentFROM dbo.TestTable ;--COMMIT ;Listing 4-6: Tab 3, when using READ_COMMITTED_SNAPSHOT isolation, the queryalso completes right away.109

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!