tsql - Understanding locking behavior in SQL Server -


i tried reproduce situation of question [1].

on table, taken , filled data wiki's "isolation (database systems)" [2],
in sql server 2008 r2 ssms, executed:

1) first in first tab (window) of ssms

-- transaction isolation level in first window not influence results (?) -- thought second transaction in 2) runs @ level set in first window  begin transaction  insert users values ( 3, 'bob', 27 ) waitfor delay '00:00:22' rollback 

2) after, in second window

-- commented/uncommented  -- set transaction isolation level serializable -- set transaction isolation level read repeatable -- set transaction isolation level read committed -- set transaction isolation level read uncommitted  select * users --with(nolock) 

update:
sorry, results corrected.

my results, depending on isolation level set in 2), select returns:

  • immediately (reading uncommitted inserted row)

    • for cases of select nolock
    • for read uncommitted (select either or without nolock)
  • is waiting completion of transaction 1) (only if select without nolock) and

    • in read committed , higher (repeatable read, serializable) transaction isolation level

these results contradict situation described in question (and explained in answers?) [1]
(for example, select nocheck waiting completion of 1)), etc.

how can results , [1] explained?


update2:
question subquestion of questions [3] (or result of them not being answered).

cited:
[1]
explain locking behavior in sql server
explain locking behavior in sql server
[2]
"isolation (database systems)"
plz add trailing ) link. cannot manage preserve here in link! http://en.wikipedia.org/wiki/isolation_(database_systems)
[3]
nolock default select statements in sql server 2005?
is nolock default select statements in sql server 2005?

there useful msdn link talk locking hints in sql 2008. maybe in example case of sql server 2008 disfavoring tables locks?

(the following snippet link below talks locks potentially being ingored sql server 2008)

as shown in following example, if transaction isolation level set serializable, , table-level locking hint nolock used select statement, key-range locks typically used maintain serializable transactions not taken.

copyuse adventureworks2008r2; go set transaction isolation level serializable; go begin transaction; go select title     humanresources.employee (nolock); go  -- information locks held  -- transaction. select           resource_type,          resource_subtype,          request_mode     sys.dm_tran_locks     request_session_id = @@spid;  -- end transaction. rollback; go 

the lock taken references humanresources.employee schema stability (sch-s) lock. in case, serializability no longer guaranteed.

in sql server 2008, lock_escalation option of lter table can disfavor table locks, , enable hobt locks on partitioned tables. option not locking hint, can used reduce lock escalation. more information, see alter table (transact-sql).


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -