Welcome to dbForumz.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

WITH ROWLOCK Hint and VIEWS

 
   Database Forums (Home) -> Programming RSS
Next:  New Feature Request for HDR/RSS in place upgrade.  
Author Message
Steve

External


Since: Oct 15, 2010
Posts: 1



(Msg. 1) Posted: Fri Oct 15, 2010 11:15 am
Post subject: WITH ROWLOCK Hint and VIEWS
Archived from groups: microsoft>public>sqlserver>programming (more info?)

We use the WITH ROWLOCK hint when we are updating a single row in a
table. We use this for both tables and views when a single row is
being updated. We are running into issues where the WITH ROWLOCK on a
VIEW is escalating to a page lock, which is the exact behavior that
WITH ROWLOCK is supposed to prevent.

One of the DBA's is speculating that the issue is that SQL Server is
somehow messing up the ROWLOCK hint on a view. Does that seem at all
reasonable? I've never heard anything like that before.

 >> Stay informed about: WITH ROWLOCK Hint and VIEWS 
Back to top
Login to vote
Erland Sommarskog2

External


Since: May 30, 2004
Posts: 1649



(Msg. 2) Posted: Fri Oct 15, 2010 11:35 pm
Post subject: Re: WITH ROWLOCK Hint and VIEWS [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Steve ( ) writes:
> We use the WITH ROWLOCK hint when we are updating a single row in a
> table. We use this for both tables and views when a single row is
> being updated. We are running into issues where the WITH ROWLOCK on a
> VIEW is escalating to a page lock, which is the exact behavior that
> WITH ROWLOCK is supposed to prevent.

If you update a single row, and you get anything else but a row-level lock,
you are missing an index.

> One of the DBA's is speculating that the issue is that SQL Server is
> somehow messing up the ROWLOCK hint on a view. Does that seem at all
> reasonable? I've never heard anything like that before.

Without knowledge of views, table and indexes, it is impossible to tell.
What I do know is that if you use hints with objects on linked server, the
hints are silently ignored.


--
Erland Sommarskog, SQL Server MVP, esquel RemoveThis @sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx

 >> Stay informed about: WITH ROWLOCK Hint and VIEWS 
Back to top
Login to vote
Jeroen Mostert

External


Since: Oct 16, 2010
Posts: 1



(Msg. 3) Posted: Sat Oct 16, 2010 8:28 am
Post subject: Re: WITH ROWLOCK Hint and VIEWS [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On 2010-10-15 20:15, Steve wrote:
> We use the WITH ROWLOCK hint when we are updating a single row in a
> table. We use this for both tables and views when a single row is
> being updated. We are running into issues where the WITH ROWLOCK on a
> VIEW is escalating to a page lock, which is the exact behavior that
> WITH ROWLOCK is supposed to prevent.
>
SQL Server does not escalate to page locks. If it escalates, it always
escalates to table locks. See
http://www.sqlskills.com/BLOGS/PAUL/post/A-SQL-Server-DBA-myth-a-day-%...330%29-
and for more detail
http://blogs.msdn.com/b/sqlserverstorageengine/archive/2006/05/17/lock...calatio

ROWLOCK only prevents SQL Server from taking page or table locks initially
(if it decides it's more worthwhile than locking rows individually). If
escalation needs to happen, it will still happen. However, as Erland has
pointed out, a single row update should normally take row locks already, so
if escalation is still happening you are facing lock memory problems.

I have no direct experience in confirming this, so if you have a profiler
trace that says lock escalation is happening differently, that would be
interesting.

--
J.
 >> Stay informed about: WITH ROWLOCK Hint and VIEWS 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
ROWLOCK usage - hi. i don't have much experience with locking using lock hints so wondered if someone could help me with usage of ROWLOCK. i am writing a number of procs which will perform validation on data prior to performing updates. i need read consistency for th...

INDEX and VIEWS - Hi all, Let say that I have a table Customer CREATE TABLE [dbo].[Customer] ( [CustomerId] [int] NOT NULL , [CustomerName] [nvarchar] (50), [CustomerAge] [int] NOT NULL ) ON [PRIMARY] GO Let say I have an index on CustomerAge. If I have a view..

3 views becoming unweildy - Hi Table T_VesselRoute { VR_VesselTrip, VR_DateTime, VR_Distance } -- shortened of course For Each { TODAY, TODAY+1, .. TODAY+6, REST } need COUNT(VR_VesselTrip), COUNT(VR_DateTime), SUM(VR_Distance) I have attempted the following solution. I'm a...

Questions about Views - For SQL 2000 and 2005 - What is the proper purpose of a view? Why should one use a veiw rather then a query or SP? Why would I avoid using a view? What are some common nameing conventions for views? What are some differences between a SQL 2000..

2008R2 Views with ORDER BY clause - I migrated a SQL Server 2000 database to 2008R2 and now my Views don't return the rows in the order specified by the ORDER BY clause. In researching this I found this article http://support.microsoft.com/kb/926292/. I have applied SP1 and the..
   Database Forums (Home) -> Programming All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]