Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / November 2008

Tip: Looking for answers? Try searching our database.

TRANSACTION ISOLATION LEVEL in a VIEW

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Chris Hough - 18 Nov 2008 17:15 GMT
Hi,
I have a view created thus:

if exists...
drop view MyView

SET QUOTED_IDENTIFIER OFF
GO

SET ANSI_NULLS ON
GO

SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED
GO

CREATE VIEW MyView
AS
.
.
.
-- end of My View

SET QUOTED_IDENTIFIER OFF
GO

SET ANSI_NULLS ON
GO

This view is created in a client database, but always executed from C# .NET
application

This view does a large number of joins, but is never used to update data.

My questions:

Does the setting of the TRANSACTION LEVEL cause all my tables
and joins to behave as if each one had a WITH (NOLOCK) clause added?

Do I actually have to have a transaction surrounding the SELECT statement
in order to use SET TRANSACTION LEVEL (it would seem so)?

What is the simplest way to cause some of my large Views to implement
completely
a NO LOCK strategy? It is obviously more convenient to have the view stored
in
the database to have the SQL necessary to accomplish my goal, but I am
unsure as
to what the implications are of executing the view from my C# windows app.
Any help would be greatly appreciated.

Chris Hough
Alex Kuznetsov - 18 Nov 2008 17:21 GMT
> Hi,
> I have a view created thus:
[quoted text clipped - 47 lines]
>
> Chris Hough

To avoid lock contention, have you considered snapshot isolation?
Chris Hough - 18 Nov 2008 18:42 GMT
Many of our clients are still on SqlServer 2000 and have no immediate plans
to upgrade, so I would prefer to have a strategy that will work for 2000
onwards.
Sylvain Lafontaine - 18 Nov 2008 19:47 GMT
> Hi,
> I have a view created thus:
[quoted text clipped - 28 lines]
>
> This view does a large number of joins, but is never used to update data.

If other processes update data than can be in the range of the View (or
Select query), then using the Nolock hint could return bad (corrupted) data
or an error message such as 601 or 605.  See for example
http://blogs.msdn.com/craigfr/archive/2007/06/12/query-failure-with-read-uncommi
tted.aspx


> My questions:
>
> Does the setting of the TRANSACTION LEVEL cause all my tables
> and joins to behave as if each one had a WITH (NOLOCK) clause added?

Absolutely not.  The View is created without any regard to the current
Transaction Isolation Level. If you want your view to behave with the NoLock
hint, then you must add it explicitely in the Create View statement.

> Do I actually have to have a transaction surrounding the SELECT statement
> in order to use SET TRANSACTION LEVEL (it would seem so)?

Not necessarily.  For example, if you use the Read Uncommitted level and
then have a select statement without an *explicit* around it, then this
select statement will still be executed like with the NoLock hint.

> What is the simplest way to cause some of my large Views to implement
> completely
> a NO LOCK strategy?

You must use the Set Transaction Isolation Level Read Uncommitted around it
when you're calling it or you must add the NoLock hint when creating your
view.

> It is obviously more convenient to have the view stored in
> the database to have the SQL necessary to accomplish my goal, but I am
[quoted text clipped - 3 lines]
>
> Chris Hough

Signature

Sylvain Lafontaine, ing.
MVP - Technologies Virtual-PC
E-mail: sylvain aei ca (fill the blanks, no spam please)

Eric Russell - 18 Nov 2008 19:48 GMT
In your example below, SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED; GO;
is part of another batch, becuause it's seperated by a GO statement. Besides,
you cannot include a use the SET statement or any other statement except
SELECT within a view.
I don't know of a way to hard code transaction isolation level within the
view, except to use the (nolock) hint. However, you can SET TRANSACTION
ISOLATION LEVEL as part of your ADO connection, prior to selecting from the
view, and this setting will remain in effect for the duration of the
connection.

> Hi,
> I have a view created thus:
[quoted text clipped - 47 lines]
>
> Chris Hough
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.