久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

為什么要同時使用 NOLOCK 和 NOWAIT?

Why use NOLOCK and NOWAIT together?(為什么要同時使用 NOLOCK 和 NOWAIT?)
本文介紹了為什么要同時使用 NOLOCK 和 NOWAIT?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

一位同事編寫了一個使用提示with (NOLOCK,NOWAIT)"的查詢.

A colleague wrote a query which uses the hints "with (NOLOCK,NOWAIT)".

例如

select first_name, last_name, age
from people with (nolock,nowait)

假設:

NOLOCK 說不用擔心任何級別的任何鎖定,現在就讀取數據"

NOLOCK says "don't worry about any locks at any level, just read the data now"

NOWAIT 說不要等待,如果表被鎖定,只會出錯"

問題:
為什么同時使用兩者?當然 NOWAIT 永遠不會被實現,因為 NOLOCK 意味著它無論如何都不會等待鎖......?

NOWAIT says "don't wait, just error if the table is locked"

Question:
Why use both at the same time? Surely NOWAIT will never be realised, as NOLOCK means it wouldn't wait for locks anyway ... ?

推薦答案

這是多余的(或者至少是無效的).在一個查詢窗口中,執行:

It's redundant (or at least, ineffective). In one query window, execute:

create table T (ID int not null)
begin transaction
alter table T add ID2 int not null

保持這個窗口打開,打開另一個查詢窗口并執行:

leave this window open, open another query window and execute:

select * from T WITH (NOLOCK,NOWAIT)

盡管有 NOWAIT 提示,并且盡管記錄為在遇到任何鎖時立即返回消息,但第二個查詢將掛起,等待 Schema 鎖.

Despite the NOWAIT hint, and despite it being documented as returning a message as soon as any lock is encountered, this second query will hang, waiting for the Schema lock.

<打擊>閱讀有關表格提示的文檔:

NOWAIT:

指示數據庫引擎在表上遇到鎖時立即返回消息

Instructs the Database Engine to return a message as soon as a lock is encountered on the table

請注意,這里指的是鎖,任何鎖.

Note that this is talking about a lock, any lock.

NOLOCK(嗯,實際上是READUNCOMMITTED):

READUNCOMMITTED 和 NOLOCK 提示僅適用于數據鎖.所有查詢,包括那些帶有 READUNCOMMITTED 和 NOLOCK 提示的查詢,都會在編譯和執行期間獲取 Sch-S(架構穩定性)鎖.因此,當并發??事務在表上持有 Sch-M(架構修改)鎖時,查詢會被阻塞.

READUNCOMMITTED and NOLOCK hints apply only to data locks. All queries, including those with READUNCOMMITTED and NOLOCK hints, acquire Sch-S (schema stability) locks during compilation and execution. Because of this, queries are blocked when a concurrent transaction holds a Sch-M (schema modification) lock on the table.

所以,NOLOCK 確實需要等待 some 鎖.

So, NOLOCK does need to wait for some locks.

這篇關于為什么要同時使用 NOLOCK 和 NOWAIT?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Converting Every Child Tags in to a Single Column with multiple Delimiters -SQL Server (3)(將每個子標記轉換為具有多個分隔符的單列-SQL Server (3))
How can I create a view from more than one table?(如何從多個表創建視圖?)
Create calculated value based on calculated value inside previous row(根據前一行內的計算值創建計算值)
How do I stack the first two columns of a table into a single column, but also pair third column with the first column only?(如何將表格的前兩列堆疊成一列,但也僅將第三列與第一列配對?) - IT屋-程序員軟件開發技
Recursive t-sql query(遞歸 t-sql 查詢)
Convert Month Name to Date / Month Number (Combinations of Questions amp; Answers)(將月份名稱轉換為日期/月份編號(問題和答案的組合))
主站蜘蛛池模板: 国产在线视频一区二区 | 久久久久国产精品一区二区 | 久久亚洲一区 | 91精品国产91久久综合桃花 | 日韩成人在线免费观看 | 国产成人综合在线 | 欧美一级免费 | av色在线 | 在线观看亚洲 | 麻豆久久久9性大片 | 亚洲a视频 | 一级中国毛片 | av手机免费在线观看 | 国产电影一区二区 | 久久久久久久久久久久亚洲 | 日本视频免费观看 | 在线免费小视频 | 免费成人高清 | 成人一区二区三区在线观看 | 一区二区中文 | 亚洲午夜视频在线观看 | 福利视频一区二区 | 国产福利精品一区 | 中文字幕成人 | 日韩欧美精品一区 | 高清国产午夜精品久久久久久 | 91精品亚洲 | 国产美女视频黄 | 国产精品高潮呻吟久久aⅴ码 | 成人动漫一区二区 | 国产欧美在线视频 | 精品欧美一区二区三区精品久久 | 欧洲视频一区二区 | 福利视频网址 | 在线色网 | 曰批视频在线观看 | 精品亚洲一区二区三区 | 久久久久久久91 | 国产一级毛片精品完整视频版 | 91欧美精品 | 精品久久久久久 |