SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Reg: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED


Reg: SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED

Author
Message
nagesh.prasad
nagesh.prasad
Valued Member
Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)Valued Member (57 reputation)

Group: General Forum Members
Points: 57 Visits: 74
Hi,

I am new to this DB Development.

Please advice, why we need this "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;" while creating SPs.

Regards,
Nagesh Prasad
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87921 Visits: 45274
You don't need it and frankly you probably shouldn't be using readuncommitted without a very good reason.

See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx
(nolock is much the same as read uncommitted, just one's a hint)

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


kevin_nikolai
kevin_nikolai
Old Hand
Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)

Group: General Forum Members
Points: 377 Visits: 523
For SQL Reports stored procedures you most definitely want to use "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED".
You only specify it once in the beginning of your stored procedure, as to having to specify with(NOLOCK) in every from clause in your stored procedure, a real time saver.

-------------------------------------------------------------------------------

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;

SELECT
firstname
,salary
FROM dbo.employee e
JOIN salary s
ON s.employeeid = s.employeeid;The comparable method using hints would be:

-------------------------------------------------------------------------------

SELECT
firstname
,salary
FROM dbo.employee e WITH (nolock)
JOIN salary s WITH (nolock)
ON s.employeeid = s.employeeid;

-------------------------------------------------------------------------------
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87921 Visits: 45274
kevin_nikolai (8/2/2013)
For SQL Reports stored procedures you most definitely want to use "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED".


Because it's really, really important for all reports to occasionally return inconsistent and incorrect data? I mean, one would never expect a report to actually be correct all the time, that's just not realistic....

See - http://blogs.msdn.com/b/davidlean/archive/2009/04/06/sql-server-nolock-hint-other-poor-ideas.aspx

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Phil Parkin
Phil Parkin
SSCoach
SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)SSCoach (18K reputation)

Group: General Forum Members
Points: 18634 Visits: 20449
kevin_nikolai (8/2/2013)
For SQL Reports stored procedures you most definitely want to use "SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED".
--


If you can guarantee that the database is and will be in a fully committed and unchanging state when the proc runs (eg if everything is in read-only mode), this should be OK. Otherwise Gail's advice is most pertinent.


Help us to help you. For better, quicker and more-focused answers to your questions, consider following the advice in this link.

If the answer to your question can be found with a brief Google search, please perform the search yourself, rather than expecting one of the SSC members to do it for you.

Please surround any code or links you post with the appropriate IFCode formatting tags. It helps readability a lot.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87921 Visits: 45274
Phil Parkin (8/2/2013)
If you can guarantee that the database is and will be in a fully committed and unchanging state when the proc runs (eg if everything is in read-only mode)


And if the DB is guaranteed to be essentially read-only at the time, then there's no real point in read uncommitted as there will be no exclusive locks that could block the report.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


kevin_nikolai
kevin_nikolai
Old Hand
Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)

Group: General Forum Members
Points: 377 Visits: 523
OK,

In SQL 2012 you can have a read-only copy of the database - which you can use for SQL Reports,
in this case you can use READ UNCOMMITTED or skip it altogether (according to Gail).

Normally you would use READ UNCOMMITTED in stored procedures of SQL Reports if they point
to Application server database - NOT to impact performance of the Application you would not worry too much about the totals that are slightly out

(I know best case scenario is not to run reports from Application server databases - but in reality not all companies can afford a data warehouse or data warehouse skilled employees).
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87921 Visits: 45274
kevin_nikolai (8/2/2013)
Normally you would use READ UNCOMMITTED in stored procedures of SQL Reports if they point
to Application server database - NOT to impact performance of the Application you would not worry too much about the totals that are slightly out


And the users of those reports know and accept that the results could be completely wrong. Not slightly off due to dirty reads, potentially way off due to missing and re-reading rows.

I've seen a report whose total was 20% off because nolock had allowed a particular row to be read twice and totalled twice into a financial report. Personally I've never met users who would be happy with reports that they know could be wrong. I have however met lots of developers who had no idea what side effects nolock/read uncommitted could have and who would close bug reports about incorrect data as 'cannot reproduce'.

p.s. Snapshot isolation. Read committed snapshot isolation. Database Snapshot. Reporting off log shipping secondary. Reporting off mirror DB. Reporting off Always On Read-only Secondary in SQL 2012.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


kevin_nikolai
kevin_nikolai
Old Hand
Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)Old Hand (377 reputation)

Group: General Forum Members
Points: 377 Visits: 523
Hi Gail, thanks for the reply, just want to confirm the following:

I assume I should rather use these -
Snapshot isolation.
Read committed snapshot isolation.
Database Snapshot.

I assume you meant don't use the following -
Reporting off log shipping secondary.
Reporting off mirror DB.
Reporting off Always On Read-only Secondary in SQL 2012.
GilaMonster
GilaMonster
SSC Guru
SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)SSC Guru (87K reputation)

Group: General Forum Members
Points: 87921 Visits: 45274
No, I'm giving you alternatives to using nolock. Which you use is up to you, all will give you accurate reports (accurate to specific points in time for some) without taking shared locks on your application DB.

Snapshot isolation. Read committed snapshot isolation. Database Snapshot. Reporting off log shipping secondary. Reporting off mirror DB. Reporting off Always On Read-only Secondary in SQL 2012.

Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

We walk in the dark places no others will enter
We stand on the bridge and no one may pass


Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search