Solved

10777 - ISOLATION LEVEL

Posted on 2014-09-13
4
258 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 46

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 46

Expert Comment

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

Featured Post

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

919 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

14 Experts available now in Live!

Get 1:1 Help Now