SQL Server lock hint on select

Posts   
 
    
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 05-Sep-2008 20:29:22   

Hi there,

I want to run a SELECT that has a WITH clause of (XLOCK).

Is there any way to specifiy this or do I need to use a sp or view?

Cheers, Ian.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39865
Joined: 17-Aug-2003
# Posted on: 07-Sep-2008 12:01:50   

You can add it with a bit of work in v2.6 to a derived class of the Sqlserver DQE, it's not build in by default. See this post: http://www.llblgen.com/TinyForum/GotoMessage.aspx?MessageID=78587&ThreadID=14111

Frans Bouma | Lead developer LLBLGen Pro
Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 08-Sep-2008 21:38:29   

I just wrapped one of the tables being joined to in my query with a view and did a simple 'SELECT * FROM tbl... WITH (XLOCK)'. Seems to work ok because all of the rows in the query are joining to this view.

It only seems to lock the view though. The underlying table I can SELECT from even when the view is being read!

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Sep-2008 11:46:04   

You'd better try Frans suggestion (a derived class of the Sqlserver DQE).

Ian avatar
Ian
User
Posts: 511
Joined: 01-Apr-2005
# Posted on: 09-Sep-2008 12:37:39   

Why had I better try the suggestion? Is what I've done not going to work?

Even though I said the underlying table was not being locked, I only need the rows retrieved with XLOCK for this one query. Just locking this one table with a view works for this one query.

Walaa avatar
Walaa
Support Team
Posts: 14993
Joined: 21-Aug-2005
# Posted on: 09-Sep-2008 13:06:22   

Even though I said the underlying table was not being locked, I only need the rows retrieved with XLOCK for this one query. Just locking this one table with a view works for this one query

Ok, I thought you had a problem with not locking the table.