Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 44,242 times

Contents

Related Categories

SQL Server Locks - Introduction

streamload

Introduction

Relational databases like Microsoft's SQL Server use locks to prevent multiple users from making conflicting modifications to a set of data: when a set of data is locked by a user, no other users can modify that same set of data until the first user finishes modifying the data and relinquishes the lock. There are exceptions, but let's not go there.

Some databases - SQL Server included - use locks to prevent users from seeing uncommitted modifications. In these systems, if UserA is modifying some set of data, UserB and all the rest of the users must wait until UserA is done modifying that data before UserB can get a shot at even reading the data, let alone modifying it.

Databases place locks at all levels of their physical hierarchies: rows, pages (typically a few KB of rows), extents (typically a few pages), entire tables, and entire databases. Some databases (Oracle, others?) only use fine-grained row locks, others don't do row locks at all and only allow rough-grained page, extent, table, and database locks. Most databases - SQL Server included - support row locking, but often use rough-grained locks. This is because lock management is a royal pain. Locks aren't small or simple entities, so if you only do row-level locking, you can get yourself into a world of pain: a million-row update can easily swamp memory and be a bear to manage.

Shameless Plug
These and many other cutting-edge techniques power Streamload.com, a digital entertainment delivery site offering unlimited free online stora

Comments

  • Re: [1688] SQL Server Locks

    Posted by Griff on 15 Feb 2007

    I've implemented the [WITH (NOLOCK)] hint and it's been a reasonable success.  The only additional note of caution I would add is that we have one table that is occasionally updated (batch ins...

  • (Dead-)locking in tables

    Posted by hvse on 23 Sep 2005

    Great.

    This little hint with those little word (nolock) saved my life - and the life of our application. (http://www.gpsoverip.de)

    Thank you VERY much ...

  • Seeing Uncommitted Data

    Posted by RAFinnerty on 29 Sep 2004

    You say (with regard to locking): "For financial code and denormalized aggregates (those little counters of related data that you stash away and try desperately to keep accurate), you should play it s...

  • Transaction logs file Management

    Posted by alok_john on 27 Oct 2003

    Please contribute your suggestion in relation with various issues related with log file management in SQL server. Such as
    1.    Methods to Shrinking the log file.
    2.    Recover the database form Log file...