標籤:
原文地址:http://www.tuicool.com/articles/qe6BZbR
也許因為它太過於簡單,自己一直沒能好好關注這個語句,只記得"只是"提高點效能而已.有時會在預存程序中寫上幾句,有時也會懶得去敲這幾個字母.但是.他們SET NOCOUNT ON 和SET NOCOUNT OFF 之間到底有多大的區別嗎?前天一時好奇.終於想弄清楚他們之間效能有多大區別.在google一遍,找了幾篇文章.我們可以得出一些結論.
How NOCOUNT affects ADO.NET (NOCOUNT對ADO.NET影響多大)by Jon Galloway
在文章的評論有一段測試的代碼,大家可以複製到查詢分析器進行測試.基本上,SET NOCOUNT ON比OFF更快點(但我測試的結果不是很理想,基本上二者相差不是太大,更誇張是文章下面的評論:
I want to share my experience with NOCOUNT.
A stored procedure who joins a few tables with more than 100.000 rows is very slow if you run it with ADO.NET and with option NOCOUNT ON. By setting NOCOUNT OFF the same procedure will be 10 times faster.
There is no difference if you execute this procedure from the Management Studio with NOCOUNT OFF or ON
MY GOD!
Seeing Is Believing
基本上他們的結論是:使用NOCOUNT能夠減少網路的傳輸.當我們SET NOCOUNT ON時執行的預存程序每執行sql語句(像
SELECT, INSERT, UPDATE, DELETE)時會忽略向用戶端發送
DONE_IN_PROC訊息.
如果我們判斷Update更新資料是否成功時,最簡便的方法就是ExecuteNonQuery()>0.在使用SET NOCOUNT ON時, ExecuteNonQuery總是返回-1 . 一個很好的解決方案就是使用out parameter方式來輸出是否成功 it uses the rows affected result to determine if the update succeeded .
另外有一篇 T-SQL 編碼通訊協定 是一篇不錯的文章.非常值得一讀.
原文地址:http://www.cnblogs.com/cnzc/archive/2007/09/01/878434.html
--------------------------------------------------------------------------
public virtual int GetMenuByRID(Nullable<int> rID)
{
var rIDParameter = rID.HasValue ?
new ObjectParameter("RID", rID) :
new ObjectParameter("RID", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("GetMenuByRID", rIDParameter);
}
ObjectContext.ExecuteFunction 這個返回的是影響的行數
關於Set Nocount ON的效能 |c#調用預存程序的傳回值總是-1