{"id":39,"date":"2007-12-07T09:44:17","date_gmt":"2007-12-07T11:44:17","guid":{"rendered":"http:\/\/www.ragestorm.net\/blogs\/?p=39"},"modified":"2007-12-07T09:57:16","modified_gmt":"2007-12-07T11:57:16","slug":"sql-setting-nocount-programmatically","status":"publish","type":"post","link":"https:\/\/www.ragestorm.net\/blogs\/?p=39","title":{"rendered":"SQL: Setting NOCOUNT Programmatically"},"content":{"rendered":"<p>As I mess with SQL at work, I learnt about some feature which is called, NOCOUNT. This feature tells the server to return the number of affected rows after each query a client does, thus most of the times wasting bandwidth for unused\/unwanted data. I was interested in setting this option server-wide. Although, some people will say it&#8217;s a bad move, because if you later have more DB&#8217;s on the server which need this feature, bla bla&#8230; But I know what I want and that&#8217;s what I will do.<\/p>\n<p>The problem was how to set it programatically, I searched the inet for a bit, but didn&#8217;t come up with anything useful. So I decided to write that snippet on my own. It&#8217;s a bit tricky, but once you see it, it looks ok.<\/p>\n<p><font face=\"courier new\"><\/p>\n<pre>\r\nUSE master;\r\nDECLARE @CurrentValue AS INT;\r\nCREATE TABLE #tmp (v VARCHAR(50), w INT, x INT, y INT, z INT);\r\nINSERT INTO #tmp\r\n      EXEC sp_configure 'User Options';\r\nSELECT @CurrentValue = y FROM #tmp;\r\nDROP TABLE #tmp;\r\nSET @CurrentValue = @CurrentValue | 512; -- 512=NOCOUNT\r\nEXEC sp_configure 'User Options', @CurrentValue;\r\nRECONFIGURE WITH OVERRIDE;\r\n<\/pre>\n<p><\/font><\/p>\n<p>The trick was how to get the results from the EXEC sp_configure so you can read them yourself, the solution was to create a temporary table which you instruct SQL to insert the results of sp_configure into that table. Later on, you can simply read from this table and do whatever you&#8217;re up to. This way we can preserve the original value and in addition set the NOCOUNT flag (512, as a bit field&#8230;).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I mess with SQL at work, I learnt about some feature which is called, NOCOUNT. This feature tells the server to return the number of affected rows after each query a client does, thus most of the times wasting bandwidth for unused\/unwanted data. I was interested in setting this option server-wide. Although, some people [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"spay_email":"","jetpack_publicize_message":""},"categories":[16],"tags":[],"jetpack_featured_media_url":"","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/pbWKd-D","_links":{"self":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/39"}],"collection":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=39"}],"version-history":[{"count":0,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=\/wp\/v2\/posts\/39\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=39"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=39"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.ragestorm.net\/blogs\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=39"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}