Solved

10777 - ISOLATION LEVEL

Posted on 2014-09-13
4
255 Views
Last Modified: 2014-09-15
hi experts

in this code
-- Retrieve the changes between the last extracted and current versions
SET TRANSACTION ISOLATION LEVEL SNAPSHOT

DECLARE @previous_version BigInt
SELECT @previous_version = MAX(LastExtractedVersion)
FROM stg.ExtractLog
WHERE SourceName = 'Salespeople'

DECLARE @current_version BigInt
SET @current_version = CHANGE_TRACKING_CURRENT_VERSION();

SELECT  @previous_version 'Previously retrieved Version',
          @current_version 'Current version',
            CT.SalesPersonID,
        r.SalespersonName,
            r.StoreName,
            r.PostalCode,
            r.City,
            r.Region,
            r.Country
FROM
CHANGETABLE(CHANGES src.Salespeople, @previous_version) CT
INNER JOIN src.Salespeople r ON CT.SalesPersonID = r.SalesPersonID

UPDATE stg.ExtractLog
SET LastExtractedVersion = @current_version
WHERE SourceName = 'Salespeople'

SET TRANSACTION ISOLATION LEVEL READ COMMITTED
GO

why use:
SET TRANSACTION ISOLATION LEVEL SNAPSHOT
and
SET TRANSACTION ISOLATION LEVEL READ COMMITTED
0
Comment
Question by:enrique_aeo
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Racim BOUDJAKDJI earned 500 total points
ID: 40321477
As Row Versionning physically separates within a transaction or a database the data that is used in a SELECT from the version that is used in the INSERT/UPDATE/DELETE statements.  

The instruction makes sure that all values used in the SELECT statement are necessarily committed values ignoring all uncommitted values (at the point in time of the transaction) but adding to them an on-the-fly value coming from CDC session.  Since this feature creates overhead, the transaction put back the normal isolation mode once the UPDATE transaction is complete.

Hope this helps.
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40322533
By the code you posted, there's two SELECT statement followed by an UPDATE, so I think the idea is to assure that you are working with the same set of data during all process, so the need for SET TRANSACTION ISOLATION LEVEL SNAPSHOT. Also, this isolation level doesn't cause locks, since it's working with a snapshot and not with the table.

At the end SET TRANSACTION ISOLATION LEVEL READ COMMITTED to going back to the default isolation level that avoids dirty reads ( cannot read data that has been modified but not committed by other transactions).
0
 

Author Comment

by:enrique_aeo
ID: 40323037
Dear Victor, your answer is very good, unfortunately I had already qualifed question, I will have a more careful next time. Thank you
0
 
LVL 45

Expert Comment

by:Vitor Montalvão
ID: 40323044
No worries Enrique. The idea is to help you. Points are secondary.
Cheers
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now