Re: select rows database lock?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Roman Rehak (rrehak_at_OPPOSITEofCOLDmail.com)
Date: 02/28/05


Date: Mon, 28 Feb 2005 00:22:10 -0500

NOLOCK helps, but you also have to attach it to every table in the select
statement. It's really best to stay away from viewing data in EM. I learned
the hard way that it can interfere with production applications. I did some
experiments and it also seemed that whether locking occurred or not was
really unpredictable, especially with views.

Roman

Roman Rehak, MCSD, MCDBA, MCSA
SQL Server Specialist
Competitive Computing
http://sqljunkies.com/WebLog/Roman

"gl" <gl@discussions.microsoft.com> wrote in message
news:90B4843D-135F-4BBA-8A0D-3CF6115E9080@microsoft.com...
> So if i go to open sql-->query then put a NOLOCK on the base select
statement
> will that solve the problem?
>
> So what i'm getting here is the database is locked until the you scroll to
> the last record? Is the best way of viewing live data just typing out
query
> statements with a nolock in the sql query tool then?
>
> "Sue Hoegemeier" wrote:
>
> > Enterprise Manager wasn't designed to be a client data tool
> > so how it retrieves records from large tables is not
> > necessarily very efficient.
> > Enterprise Manager will need to consume the entire recordset
> > to have the locks released. You need to scroll to the last
> > record in Enterprise Manager to have the locks
> > released. You would have an IS lock on the table and a
> > shared lock on the specific page you are on until moving to
> > the end of the result set.
> > A shared lock is not compatible with an exclusive lock.
> > Exclusive locks are needed for updates.
> >
> > -Sue
> >
> > On Fri, 25 Feb 2005 05:47:02 -0800, "gl"
> > <gl@discussions.microsoft.com> wrote:
> >
> > >When in the sql enterprise manager, if you right click a table and go
to open
> > >table--> select all rows, does that "lock" the database? As in if you
select
> > >all rows will someone else trying to read the data (via app or web
interface)
> > >and update it be locked out of it? We're often told that we shouldn't
use
> > >this method at our work and we should only run statements with nolocks
on
> > >live data. I had always thought that the data only locks when you put
the
> > >cursor in one of the rows to actually edit it.
> > >
> > >What is the correct ruling? I could do tests myself but i'm not sure
they
> > >would be accurate. I mainly want to know what happens when you select
all
> > >rows (or select top) but don't put your cursor in the data.
> >
> >



Relevant Pages

  • Re: Transaction problem (delete / select)
    ... > I can't use nolock because it's the same as read uncommited. ... Are you saying that it doesn't work, or are you saying that you cannot allow dirty reads? ... Tibor Karaszi, SQL Server MVP ... >> Oracle shows the user the table as it was before the lock. ...
    (microsoft.public.sqlserver.server)
  • Re: Deadlocks during SqlDataReader.Read method
    ... Whether NOLOCK is good or bad is completely subjective to what you are ... is to determine which lock is being used has this might have a strong ... > described "bad" ways to fix the problem. ... > the READER when the ExecuteReader is attempting this read. ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Question on Locks
    ... The mode and Type of the the lock are important here. ... > Even the default Transaction Isolation Level is Read Committed which means> I should be able to read those records that are already committed, ... >> Use NOLOCK and READPAST sparingly. ... >> If you run the same with the NOLOCK hint, you'll get results instantly ->> but you'll see Clinton being born in 2002, in violation of the business>> rule! ...
    (microsoft.public.sqlserver.programming)
  • Re: Transaction problem (delete / select)
    ... I can't use nolock because it's the same as read uncommited. ... The readpast hangs, while the transaction is running. ... > Oracle shows the user the table as it was before the lock. ...
    (microsoft.public.sqlserver.server)
  • RE: Prevent deadlock in select
    ... you can use the hint "nolock" with the select statement. ... Eg. select from with nolock... ... Will this solve the deadlock problem? ... How do I lock a set of tables at the same time? ...
    (microsoft.public.sqlserver.programming)