{"id":2161,"date":"2012-06-05T07:42:33","date_gmt":"2012-06-05T07:42:33","guid":{"rendered":"http:\/\/enjoyasp.net\/?p=2161"},"modified":"2012-11-15T12:27:39","modified_gmt":"2012-11-15T12:27:39","slug":"%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%9c%a8%e7%a8%8b%e5%ba%8f%e6%85%a2%e8%80%8c%e5%9c%a8management-studio%e5%bf%ab%e7%9a%84%e5%8e%9f%e5%9b%a0","status":"publish","type":"post","link":"https:\/\/enjoyasp.net\/index.php\/2012\/06\/05\/%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%9c%a8%e7%a8%8b%e5%ba%8f%e6%85%a2%e8%80%8c%e5%9c%a8management-studio%e5%bf%ab%e7%9a%84%e5%8e%9f%e5%9b%a0\/","title":{"rendered":"\u5b58\u50a8\u8fc7\u7a0b\u5728\u7a0b\u5e8f\u6162\u800c\u5728Management Studio\u5feb\u7684\u539f\u56e0"},"content":{"rendered":"<p>1\uff0c\u5b58\u50a8\u8fc7\u7a0b\u5728\u7a0b\u5e8f\u6162\u800c\u5728Management Studio\u5feb\uff0c\u5206\u6790\u67e5\u8be2\u8ba1\u5212\uff0c\u53d1\u73b0\u751f\u6210\u4e86\u4e24\u4e2a\u6267\u884c\u8ba1\u5212\uff0c\u8bf4\u660e\u4e8c\u8005\u7528\u7684\u4e0d\u662f\u540c\u4e00\u4e2a\u67e5\u8be2\u8ba1\u5212\uff0c\u56e0\u53c2\u6570\u55c5\u63a2\u95ee\u9898\u5f15\u53d1\u6b64\u79cd\u60c5\u51b5\u3002<br \/>\n2\uff0c\u4ea7\u751f\u4e0d\u540c\u6267\u884c\u8ba1\u5212\u539f\u56e0\u662f\uff1a\u5f15\u8d77\u6267\u884c\u8ba1\u5212\u91cd\u65b0\u7f16\u8bd1\u7684\u539f\u56e0\u4e4b\u4e00\u662f\u4e0a\u4e0b\u6587\u73af\u5883\u53d1\u751f\u6539\u53d8\uff0cSET\u5f00\u5173\u3002\u8fd9\u4e9b\u5f00\u5173\u4f1a\u5f71\u54cd\u8bed\u53e5\u6267\u884c\u7684\u884c\u4e3a\uff0c\u751a\u81f3\u5e26\u6765\u4e0d\u540c\u7684\u7ed3\u679c\uff0c\u800csqlserver\u8981\u53e6\u751f\u6210\u65b0\u7684\u7f16\u8bd1\u8ba1\u5212\u3002\u800c\u5728Management Studio\u4e2d\uff0c\u9ed8\u8ba4\u6253\u5f00\u4e86SET ARITHABORT ON \u5728\u67e5\u8be2\u6267\u884c\u8fc7\u7a0b\u4e2d\u53d1\u751f\u6ea2\u51fa\u6216\u88ab\u96f6\u9664\u9519\u8bef\u65f6\uff0c\u7ec8\u6b62\u67e5\u8be2\uff0c\u800c\u7a0b\u5e8f\u4e2d\u662f\u4e0d\u6253\u5f00\u7684\uff0c\u4e0d\u540c\u7684SET\u5f00\u5173\uff0c\u9020\u6210\u4e0d\u540c\u7f16\u8bd1\u8ba1\u5212\u7684\u751f\u6210\uff0c\u800c\u4e0d\u662f\u91cd\u7528\u3002<br \/>\n<span style=\"font-size:18px;\"><strong>\u6700\u7ec8\u8bbe\u7f6e\uff1a\u770b\u5b58\u50a8\u8fc7\u7a0b\u7528\u7684\u4ec0\u4e48set,\u5c06Manage Studio\u5de5\u5177-\u9009\u9879-\u67e5\u8be2\u6267\u884c-\u9ad8\u7ea7 \u6253\u5f00\u6216\u5173\u6389\u5de5\u5177<\/strong><\/span><br \/>\n3\uff0c\u6545\u8981\u91cd\u7528\u7a0b\u5e8f\u6240\u751f\u6210\u7684\u6267\u884c\u8ba1\u5212\uff0c\u65b9\u5f0f\u662f\uff1a1\uff09\u786e\u5b9aSET\u8bbe\u7f6e 2\uff09\u5728\u5f53\u524d\u4e2d\u8bbe\u7f6e\u4e0a\u4e0b\u6587\u73af\u5883<\/p>\n<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\n--\u67e5\u627eSET\u5f00\u5173\r\n\u65b9\u6cd51\uff1a\r\nSELECT sql,setopts\r\nFROM sys.syscacheobjects\r\nWHERE OBJECT_NAME(objid,DB_ID()) = &#39;frmUser_sel&#39;\r\n\r\n\u65b9\u6cd52\uff1a\r\nSELECT plan_handle,usecounts,pvt.set_options, pvt.sql_handle\r\nFROM (\r\n    SELECT plan_handle, epa.attribute, epa.value ,usecounts\r\n    FROM sys.dm_exec_cached_plans \r\n    CROSS APPLY sys.dm_exec_sql_text(plan_handle) qt\r\n    OUTER APPLY sys.dm_exec_plan_attributes(plan_handle) AS epa\r\n    WHERE cacheobjtype = &#39;Compiled Plan&#39;\r\n    AND  OBJECT_NAME(objectid,dbid) = &#39;frmUser_sel&#39; AND dbid = DB_ID()\r\n    ) AS ecpa \r\nPIVOT (MAX(ecpa.value) FOR ecpa.attribute IN (&quot;set_options&quot;, &quot;sql_handle&quot;)) AS pvt;\r\nGO\r\n\r\n\r\n\r\n--\u5c06\u83b7\u53d6\u7684\u503c\u4f20\u5165\uff0c\u83b7\u53d6\u5177\u4f53SET\u9879\r\ndeclare @set_options INT\r\nSET @set_options= 251\r\n<\/pre>\n<div>\n\t&nbsp;<\/div>\n<div>\n<pre class=\"brush:sql;first-line:1;pad-line-numbers:true;highlight:null;collapse:false;\">\r\nIF ( (1 &amp; @options) = 1 ) PRINT &#39;DISABLE_DEF_CNST_CHK&#39;&nbsp;<\/pre>\n<\/div>\n<div>\n\tIF ( (2 &amp; @options) = 2 ) PRINT &#39;IMPLICIT_TRANSACTIONS&#39;&nbsp;<\/div>\n<div>\n\tIF ( (4 &amp; @options) = 4 ) PRINT &#39;CURSOR_CLOSE_ON_COMMIT&#39;&nbsp;<\/div>\n<div>\n\tIF ( (8 &amp; @options) = 8 ) PRINT &#39;ANSI_WARNINGS&#39;&nbsp;<\/div>\n<div>\n\tIF ( (16 &amp; @options) = 16 ) PRINT &#39;ANSI_PADDING&#39;&nbsp;<\/div>\n<div>\n\tIF ( (32 &amp; @options) = 32 ) PRINT &#39;ANSI_NULLS&#39;&nbsp;<\/div>\n<div>\n\tIF ( (64 &amp; @options) = 64 ) PRINT &#39;ARITHABORT&#39;&nbsp;<\/div>\n<div>\n\tIF ( (128 &amp; @options) = 128 ) PRINT &#39;ARITHIGNORE&#39;<\/div>\n<div>\n\tIF ( (256 &amp; @options) = 256 ) PRINT &#39;QUOTED_IDENTIFIER&#39;&nbsp;<\/div>\n<div>\n\tIF ( (512 &amp; @options) = 512 ) PRINT &#39;NOCOUNT&#39;&nbsp;<\/div>\n<div>\n\tIF ( (1024 &amp; @options) = 1024 ) PRINT &#39;ANSI_NULL_DFLT_ON&#39;&nbsp;<\/div>\n<div>\n\tIF ( (2048 &amp; @options) = 2048 ) PRINT &#39;ANSI_NULL_DFLT_OFF&#39;&nbsp;<\/div>\n<div>\n\tIF ( (4096 &amp; @options) = 4096 ) PRINT &#39;CONCAT_NULL_YIELDS_NULL&#39;&nbsp;<\/div>\n<div>\n\tIF ( (8192 &amp; @options) = 8192 ) PRINT &#39;NUMERIC_ROUNDABORT&#39;&nbsp;<\/div>\n<div>\n\tIF ( (16384 &amp; @options) = 16384 ) PRINT &#39;XACT_ABORT&#39;<\/div>\n<div>\n<p>&#8211;\u67e5\u770b\u5f53\u524doption select @@option \u53c2\u8003\uff1a<a href=\"http:\/\/www.mssqltips.com\/sqlservertip\/1415\/determining-set-options-for-a-current-session-in-sql-server\/\">Set Options<\/a>\n<\/div>\n<p>4\uff0c\u4e0a\u8ff0\u8bf4\u660e\u4e86\u76f8\u540c\u7684\u5b58\u50a8\u8fc7\u7a0b\u53c2\u6570\uff0c\u4f46\u4ea7\u751f\u4e0d\u540c\u7684\u6267\u884c\u8ba1\u5212\u7684\u539f\u56e0\uff0c\u4f46\u5173\u4e8e\u901f\u5ea6\u4e0d\u4e00\u6837\u5462\uff0c\u539f\u56e0\u662f\u53d1\u751f\u4e86\u53c2\u6570\u55c5\u63a2\uff0c\u89e3\u51b3\u53c2\u6570\u55c5\u63a2\u65b9\u6cd5\u6709\uff1a1\uff09\u91cd\u65b0\u7f16\u8bd1\u5b58\u50a8\u8fc7\u7a0b sp_recompile &#39;sp&#39; 2)\u5728\u5173\u952e\u8bed\u53e5\u52a0\uff1aoption(recompile) 3)\u6307\u5b9a\u503c<span style=\"font-weight: bold\">OPTION (OPTIMIZE FOR (@pid = 897))<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>1\uff0c\u5b58\u50a8\u8fc7\u7a0b\u5728\u7a0b\u5e8f\u6162\u800c\u5728Management Studio\u5feb\uff0c\u5206\u6790\u67e5\u8be2\u8ba1\u5212\uff0c\u53d1\u73b0\u751f\u6210\u4e86\u4e24\u4e2a\u6267\u884c\u8ba1\u5212\uff0c\u8bf4\u660e\u4e8c\u8005\u7528 [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[36],"tags":[],"class_list":["post-2161","post","type-post","status-publish","format-standard","hentry","category-sql-server"],"blocksy_meta":[],"_links":{"self":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2161","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/comments?post=2161"}],"version-history":[{"count":0,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/posts\/2161\/revisions"}],"wp:attachment":[{"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/media?parent=2161"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/categories?post=2161"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/enjoyasp.net\/index.php\/wp-json\/wp\/v2\/tags?post=2161"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}