iT邦幫忙

3

[MS SQL] 什麼是SET NOCOUNT ON

開發環境
MS SQL 2014

select 1 union select 1111
select c1=@@ROWCOUNT  

結果如下
https://ithelp.ithome.com.tw/upload/images/20180608/20106764gIwJTRsMP4.png

訊息如下
https://ithelp.ithome.com.tw/upload/images/20180608/20106764T1yFeTxX5D.png

使用後

SET NOCOUNT ON;
select 1 union select 1111
select c1=@@ROWCOUNT
 

結果如下
https://ithelp.ithome.com.tw/upload/images/20180608/20106764gIwJTRsMP4.png

訊息如下
https://ithelp.ithome.com.tw/upload/images/20180608/20106764bC4X8WKD9W.png

測試結果
1.不回傳受影響的資料列(可節省網路傳輸),通常如果沒有要看的話,會寫不回傳,又能節省網路傳輸)
2.雖然不回傳,但不影響@@ROWCOUNT,所以如果想知道影響的資料列,還是能用@@ROWCOUNT來讀取


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中
1
Ho.Chun
iT邦新手 5 級 ‧ 2019-09-27 14:41:36

簡單明瞭! 感謝 /images/emoticon/emoticon41.gif

圓頭人 iT邦研究生 5 級 ‧ 2019-09-27 16:49:46 檢舉

^^謝謝你的喜歡!!

0
iT邦新手 4 級 ‧ 2019-10-20 14:39:22

/images/emoticon/emoticon42.gif
感謝

0
e7822501
iT邦新手 5 級 ‧ 2020-06-09 09:32:18

明瞭簡單 讚讚

0
itbubble
iT邦新手 5 級 ‧ 2021-08-13 10:54:53

很清楚的說明~/images/emoticon/emoticon41.gif

我要留言

立即登入留言