Re: Repeatable read. What is it exactly...

From: Kalen Delaney (replies_at_public_newsgroups.com)
Date: 12/01/04


Date: Tue, 30 Nov 2004 19:45:03 -0800

Repeatable read and serializable are very similar, and your question is far
from stupid.

In repeatable read, SQL Server will hold locks on the data you have read
until the end of the transaction. (Normally, in read committed, locks on
data you have read are released as soon as you are done reading.) So no one
can change change the data until you commit or rollback. Updates and deletes
are not permitted.

Serializable prevents INSERTS of new data that satisfy a condition that you
used for searching.

Example

BEGIN TRAN

SELECT * FROM titles
WHERE price < 5

-- suppose the above returns 2 rows; in repeatable read, those two rows are
now locked and no one can change them
-- until you commit or rollback; but someone in another connection could
insert a whole new row with price < 5

-- So, in serializable you are absolutely guaranteed that if you run the
exact SELECT again, you will get the same result:

SELECT * FROM titles
WHERE price < 5

-- But, in repeatable read, you might get more rows back, because of
inserts.

COMMIT TRAN

In repeatable read, SQL Server locks the data you read.
In serializable, SQL Server locks the data and the 'gaps' between the data.

-- 
HTH
----------------
Kalen Delaney
SQL Server MVP
www.SolidQualityLearning.com
"Ant" <Ant@discussions.microsoft.com> wrote in message 
news:78571FC8-E575-4D1C-BA59-E07C2C176A80@microsoft.com...
> Sorry for such a basic question but what exactly is a Repeatable read as 
> far
> as transaction Isolation levels go. I understand the concept of 
> serializable,
> read committed & read uncommitted but i can't find any documentation that
> describes the repeatable read level. How does this isolation level affect
> concurrency. Sorry for such a stoopid question but it woud really help if 
> I
> got the low down once & for all. Many thanks in advance.
> Ant 


Relevant Pages

  • ISOLATION levels and when to use SERIALIZEABLE
    ... It seems to me that isolation levels only affect reads ... If the transaction contains only INSERT, UPDATE or DELETE, isolation level ... doesn't matter since they all use X locks. ... COMMIT -- or ROLLBACK ...
    (microsoft.public.sqlserver.programming)
  • Re: Row-X (SX) lock on materialized view
    ... :>: refresh logs to check against. ... :> I have been asked to check why an application has locking issues, ... :> One key table typically has a dozen row locks (users editing in the main ... The commit merely means it ...
    (comp.databases.oracle.misc)
  • Re: row vs page locking...
    ... so they automatically escalate to page level locks. ... 'Lock Escalation' - see Books Online. ... SQL Server 2005 is going to have a Snapshot ... Good old fashioned locking is less sexy, but I find, more productive! ...
    (microsoft.public.sqlserver.server)
  • Re: Locking in SQL Server and Oracle
    ... I am glad you would like to stay with SQL Server :-) ... > hard it would be to convert to Oracle during our next PeopleSoft upgrade. ... > had thought that since databases are databases, tables are tables, and SQL ... > uses row-level locks exclusively. ...
    (microsoft.public.sqlserver.server)
  • Re: Database Blocking Redux
    ... SQL Server stores rows on pages and pages on extents. ... Given the number of locks to manage, it's rare for SQL Server to lock individual rows. ... If SQL Server finds there are too many pages locked, it escalates locks to the entire extent and then to the entire table. ... When reading rows using SqlDataReader, does reading the next row release the lock on the previous row? ...
    (microsoft.public.dotnet.framework.adonet)