set transaction isolation level.pdf

Upload: davy7569

Post on 14-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/27/2019 SET TRANSACTION ISOLATION LEVEL.pdf

    1/2

    14/05/13 SET TRANSACTION ISOLATION LEVEL

    msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx 1/2

    SET TRANSACTION ISOLATION LEVEL

    Controls the default transaction locking behavior for all Microsoft SQL Server SELECT statements issued

    by a connection.

    Syntax

    SET TRANSACTION ISOLATION LEVEL

    { READ COMMITTED

    | READ UNCOMMITTED

    | REPEATABLE READ

    | SERIALIZABLE

    }

    Arguments

    READ COMMITTED

    Specifies that shared locks are held while the data is being read to avoid dirty reads, but the data can be

    changed before the end of the transaction, resulting in nonrepeatable readsor phantom data. This optionis the SQL Server default.

    READ UNCOMMITTED

    Implements dirty read, or isolation level 0 locking, which means that no shared locks are issued and no

    exclusive locks are honored. When this option is set, it is possible to read uncommitted or dirty data; values

    in the data can be changed and rows can appear or disappear in the data set before the end of the

    transaction. This option has the same effect as setting NOLOCK on all tables in all SELECT statements in atransaction. This is the least restrictive of the four isolation levels.

    REPEATABLE READ

    Locks are placed on all data that is used in a query, preventing other users from updating the data, but ne

    phantom rows can be inserted into the data set by another user and are included in later reads in the

    current transaction. Because concurrency is lower than the default isolation level, use this option only when

    necessary.

    SERIALIZABLE

    Places a range lock on the data set, preventing other users from updating or inserting rows into the data

    set until the transaction is complete. This is the most restrictive of the four isolation levels. Because

    concurrency is lower, use this option only when necessary. This option has the same effect as setting

    HOLDLOCK on all tables in all SELECT statements in a transaction.

    Remarks

    Only one of the options can be set at a time, and it remains set for that connection until it is explicitly

    changed. This becomes the default behavior unless an optimization option is specified at the table level in

    the FROM clause of the statement.

    The setting of SET TRANSACTION ISOLATION LEVEL is set at execute or run time and not at parse time.

    Examples

    This example sets the TRANSACTION ISOLATION LEVEL for the session. For each Transact-SQL statement

    that follows, SQL Server holds all of the shared locks until the end of the transaction.

    SQL Server 2000 48 out of 72 rated this helpful

    http://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:nonrepeatable_readhttp://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:phantomhttp://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:dirty_readhttp://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:phantomhttp://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:nonrepeatable_readhttp://msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx#sql:dirty_read
  • 7/27/2019 SET TRANSACTION ISOLATION LEVEL.pdf

    2/2

    14/05/13 SET TRANSACTION ISOLATION LEVEL

    msdn.microsoft.com/en-us/library/aa259216(d=printer,v=sql.80).aspx 2/2

    SET TRANSACTION ISOLATION LEVEL REPEATABLE READ

    GO

    BEGIN TRANSACTION

    SELECT * FROM publishers

    SELECT * FROM authors

    ...

    COMMIT TRANSACTION

    See Also

    Adjusting Transaction Isolation Levels

    DBCC USEROPTIONS

    Isolation Levels

    SELECT

    SET

    2013 Microsoft. All rights reserved.

    http://msdn.microsoft.com/en-us/library/aa259205(v=sql.80).aspxhttp://msdn.microsoft.com/en-us/library/aa259187(v=sql.80).aspxhttp://msdn.microsoft.com/en-us/library/aa179207(v=sql.80).aspxhttp://msdn.microsoft.com/en-us/library/aa258811(v=sql.80).aspxhttp://msdn.microsoft.com/en-us/library/aa213071(v=sql.80).aspx