SQLServer type of lock and lock principle

1, the use of the lock

  • In order to avoid the same time compete for resources database, the database is locked, only the user can use to get the key;

2, the lock granularity

  •    Line Lock (Row) ---> Page Lock (Page) ---> District lock (Partition 8 pages) ----> lock table (Table)

3, the lock type

  • Shared lock: read-only data for all operations (SELECT);
  • Modify locks: lock the resource may be used to modify (Update) in the modify operation initialization phase;
  • Exclusive lock :( exclusive lock) to modify the data reserved; (exclusive lock can not be compatible with other locks)
  • Schema locks: locks into structure modification (Sch-M) and a structural stability lock (Sch-S);
  • Intention locks: Description eligible SQL Server shared lock or an exclusive lock intention underlying resource; (contains three types: intent exclusive locks (IX), and IS intent share lock intent exclusive shared lock)
  • Bulk copy lock: Lock using bulk data modification bulk copy;

4, view the database locks

  • DMV system function: sys.dm_tran_locks

Guess you like

Origin www.cnblogs.com/dingou/p/11079983.html