{"id":52,"date":"2007-08-24T10:03:45","date_gmt":"2007-08-24T02:03:45","guid":{"rendered":"http:\/\/www.cnmiss.cn\/?p=51"},"modified":"2010-12-02T06:31:45","modified_gmt":"2010-12-02T06:31:45","slug":"sql%e5%ad%98%e5%82%a8%e8%bf%87%e7%a8%8b%e5%ae%8c%e5%85%a8%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/www.cnmiss.cn\/?p=52","title":{"rendered":"SQL\u5b58\u50a8\u8fc7\u7a0b\u5b8c\u5168\u6559\u7a0b"},"content":{"rendered":"<p><b><span style=\"font-size:12pt\">1.SQL\u5b58\u50a8\u8fc7\u7a0b\u6982\u8ff0<\/span><\/b><\/p>\n<p>\u5728\u5927\u578b\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff0c\u5b58\u50a8\u8fc7\u7a0b\u548c\u89e6\u53d1\u5668\u5177\u6709\u5f88\u91cd\u8981\u7684\u4f5c\u7528\u3002\u65e0\u8bba\u662f\u5b58\u50a8\u8fc7\u7a0b\u8fd8\u662f\u89e6\u53d1\u5668\uff0c\u90fd\u662fSQL \u8bed\u53e5\u548c\u6d41\u7a0b\u63a7\u5236\u8bed\u53e5\u7684\u96c6\u5408\u3002\u5c31\u672c\u8d28\u800c\u8a00\uff0c\u89e6\u53d1\u5668\u4e5f\u662f\u4e00\u79cd\u5b58\u50a8\u8fc7\u7a0b\u3002\u5b58\u50a8\u8fc7\u7a0b\u5728\u8fd0\u7b97\u65f6\u751f\u6210\u6267\u884c\u65b9\u5f0f\uff0c\u6240\u4ee5\uff0c\u4ee5\u540e\u5bf9\u5176\u518d\u8fd0\u884c\u65f6\u5176\u6267\u884c\u901f\u5ea6\u5f88\u5feb\u3002SQL Server 2000 \u4e0d\u4ec5\u63d0\u4f9b\u4e86\u7528\u6237\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u7684\u529f\u80fd\uff0c\u800c\u4e14\u4e5f\u63d0\u4f9b\u4e86\u8bb8\u591a\u53ef\u4f5c\u4e3a\u5de5\u5177\u4f7f\u7528\u7684\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>\n<p><b>\u5b58\u50a8\u8fc7\u7a0b\u7684\u6982\u5ff5<\/b><\/p>\n<p>     \u5b58\u50a8\u8fc7\u7a0b\uff08Stored Procedure\uff09\u662f\u4e00\u7ec4\u4e3a\u4e86\u5b8c\u6210\u7279\u5b9a\u529f\u80fd\u7684SQL \u8bed\u53e5\u96c6\uff0c\u7ecf\u7f16\u8bd1\u540e\u5b58\u50a8\u5728\u6570\u636e\u5e93\u3002\u4e2d\u7528\u6237\u901a\u8fc7\u6307\u5b9a\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u5b57\u5e76\u7ed9\u51fa\u53c2\u6570\uff08\u5982\u679c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u5e26\u6709\u53c2\u6570\uff09\u6765\u6267\u884c\u5b83\u3002<\/p>\n<p>     \u5728SQL Server \u7684\u7cfb\u5217\u7248\u672c\u4e2d\u5b58\u50a8\u8fc7\u7a0b\u5206\u4e3a\u4e24\u7c7b\uff1a\u7cfb\u7edf\u63d0\u4f9b\u7684\u5b58\u50a8\u8fc7\u7a0b\u548c\u7528\u6237\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u3002\u7cfb\u7edf\u8fc7\u7a0b\u4e3b\u8981\u5b58\u50a8\u5728master \u6570\u636e\u5e93\u4e2d\u5e76\u4ee5sp_\u4e3a\u524d\u7f00\uff0c\u5e76\u4e14\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\u4e3b\u8981\u662f\u4ece\u7cfb\u7edf\u8868\u4e2d\u83b7\u53d6\u4fe1\u606f\uff0c\u4ece\u800c\u4e3a\u7cfb\u7edf\u7ba1\u7406\u5458\u7ba1\u7406SQL Server \u63d0\u4f9b\u652f\u6301\u3002\u901a\u8fc7\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\uff0cMS SQL Server \u4e2d\u7684\u8bb8\u591a\u7ba1\u7406\u6027\u6216\u4fe1\u606f\u6027\u7684\u6d3b\u52a8\uff08\u5982\u4e86\u89e3\u6570\u636e\u5e93\u5bf9\u8c61\u3001\u6570\u636e\u5e93\u4fe1\u606f\uff09\u90fd\u53ef\u4ee5\u88ab\u987a\u5229\u6709\u6548\u5730\u5b8c\u6210\u3002\u5c3d\u7ba1\u8fd9\u4e9b\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\u88ab\u653e\u5728master \u6570\u636e\u5e93\u4e2d\uff0c\u4f46\u662f\u4ecd\u53ef\u4ee5\u5728\u5176\u5b83\u6570\u636e\u5e93\u4e2d\u5bf9\u5176\u8fdb\u884c\u8c03\u7528\uff0c\u5728\u8c03\u7528\u65f6\u4e0d\u5fc5\u5728\u5b58\u50a8\u8fc7\u7a0b\u540d\u524d\u52a0\u4e0a\u6570\u636e\u5e93\u540d\u3002\u800c\u4e14\u5f53\u521b\u5efa\u4e00\u4e2a\u65b0\u6570\u636e\u5e93\u65f6\uff0c\u4e00\u4e9b\u7cfb\u7edf\u5b58\u50a8\u8fc7\u7a0b\u4f1a\u5728\u65b0\u6570\u636e\u5e93\u4e2d\u88ab\u81ea\u52a8\u521b\u5efa\u3002\u7528\u6237\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u662f\u7531\u7528\u6237\u521b\u5efa\u5e76\u80fd\u5b8c\u6210\u67d0\u4e00\u7279\u5b9a\u529f\u80fd\uff08\u5982\u67e5\u8be2\u7528\u6237\u6240\u9700\u6570\u636e\u4fe1\u606f\uff09\u7684\u5b58\u50a8\u8fc7\u7a0b\u3002\u5728\u672c\u7ae0\u4e2d\u6240\u6d89\u53ca\u5230\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e3b\u8981\u662f\u6307\u7528\u6237\u81ea\u5b9a\u4e49\u5b58\u50a8\u8fc7\u7a0b\u3002<\/p>\n<p><b>\u5b58\u50a8\u8fc7\u7a0b\u7684\u4f18\u70b9<\/b><\/p>\n<p>     \u5f53\u5229\u7528MS SQL Server \u521b\u5efa\u4e00\u4e2a\u5e94\u7528\u7a0b\u5e8f\u65f6\uff0cTransaction-SQL \u662f\u4e00\u79cd\u4e3b\u8981\u7684\u7f16\u7a0b\u8bed\u8a00\u3002\u82e5\u8fd0\u7528Transaction-SQL \u6765\u8fdb\u884c\u7f16\u7a0b\uff0c\u6709\u4e24\u79cd\u65b9\u6cd5\u3002\u5176\u4e00\u662f\uff0c\u5728\u672c\u5730\u5b58\u50a8Transaction- SQL \u7a0b\u5e8f\uff0c\u5e76\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u5411SQL Server \u53d1\u9001\u547d\u4ee4\u6765\u5bf9\u7ed3\u679c\u8fdb\u884c\u5904\u7406\u3002\u5176\u4e8c\u662f\uff0c\u53ef\u4ee5\u628a\u90e8\u5206\u7528Transaction-SQL \u7f16\u5199\u7684\u7a0b\u5e8f\u4f5c\u4e3a\u5b58\u50a8\u8fc7\u7a0b\u5b58\u50a8\u5728SQL Server \u4e2d\uff0c\u5e76\u521b\u5efa\u5e94\u7528\u7a0b\u5e8f\u6765\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5bf9\u6570\u636e\u7ed3\u679c\u8fdb\u884c\u5904\u7406\u5b58\u50a8\u8fc7\u7a0b\u80fd\u591f\u901a\u8fc7\u63a5\u6536\u53c2\u6570\u5411\u8c03\u7528\u8005\u8fd4\u56de\u7ed3\u679c\u96c6\uff0c\u7ed3\u679c\u96c6\u7684\u683c\u5f0f\u7531\u8c03\u7528\u8005\u786e\u5b9a\uff1b\u8fd4\u56de\u72b6\u6001\u503c\u7ed9\u8c03\u7528\u8005\uff0c\u6307\u660e\u8c03\u7528\u662f\u6210\u529f\u6216\u662f\u5931\u8d25\uff1b\u5305\u62ec\u9488\u5bf9\u6570\u636e\u5e93\u7684\u64cd\u4f5c\u8bed\u53e5\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u8c03\u7528\u53e6\u4e00\u5b58\u50a8\u8fc7\u7a0b\u3002 <\/p>\n<p>     \u6211\u4eec\u901a\u5e38\u66f4\u504f\u7231\u4e8e\u4f7f\u7528\u7b2c\u4e8c\u79cd\u65b9\u6cd5\uff0c\u5373\u5728SQL Server \u4e2d\u4f7f\u7528\u5b58\u50a8\u8fc7\u7a0b\u800c\u4e0d\u662f\u5728\u5ba2\u6237\u8ba1\u7b97\u673a\u4e0a\u8c03\u7528Transaction-SQL \u7f16\u5199\u7684\u4e00\u6bb5\u7a0b\u5e8f\uff0c\u539f\u56e0\u5728\u4e8e\u5b58\u50a8\u8fc7\u7a0b\u5177\u6709\u4ee5\u4e0b\u4f18\u70b9\uff1a<\/p>\n<p>     \uff081\uff09 \u5b58\u50a8\u8fc7\u7a0b\u5141\u8bb8\u6807\u51c6\u7ec4\u4ef6\u5f0f\u7f16\u7a0b<\/p>\n<p>     \u5b58\u50a8\u8fc7\u7a0b\u5728\u88ab\u521b\u5efa\u4ee5\u540e\u53ef\u4ee5\u5728\u7a0b\u5e8f\u4e2d\u88ab\u591a\u6b21\u8c03\u7528\uff0c\u800c\u4e0d\u5fc5\u91cd\u65b0\u7f16\u5199\u8be5\u5b58\u50a8\u8fc7\u7a0b\u7684SQL \u8bed\u53e5\u3002\u800c\u4e14\u6570\u636e\u5e93\u4e13\u4e1a\u4eba\u5458\u53ef\u968f\u65f6\u5bf9\u5b58\u50a8\u8fc7\u7a0b\u8fdb\u884c\u4fee\u6539\uff0c\u4f46\u5bf9\u5e94\u7528\u7a0b\u5e8f\u6e90\u4ee3\u7801\u6beb\u65e0\u5f71\u54cd\uff08\u56e0\u4e3a\u5e94\u7528\u7a0b\u5e8f\u6e90\u4ee3\u7801\u53ea\u5305\u542b\u5b58\u50a8\u8fc7\u7a0b\u7684\u8c03\u7528\u8bed\u53e5\uff09\uff0c\u4ece\u800c\u6781\u5927\u5730\u63d0\u9ad8\u4e86\u7a0b\u5e8f\u7684\u53ef\u79fb\u690d\u6027\u3002<\/p>\n<p>     \uff082\uff09 \u5b58\u50a8\u8fc7\u7a0b\u80fd\u591f\u5b9e\u73b0\u8f83\u5feb\u7684\u6267\u884c\u901f\u5ea6<\/p>\n<p>     \u5982\u679c\u67d0\u4e00\u64cd\u4f5c\u5305\u542b\u5927\u91cf\u7684Transaction-SQL \u4ee3\u7801\u6216\u5206\u522b\u88ab\u591a\u6b21\u6267\u884c\uff0c\u90a3\u4e48\u5b58\u50a8\u8fc7\u7a0b\u8981\u6bd4\u6279\u5904\u7406\u7684\u6267\u884c\u901f\u5ea6\u5feb\u5f88\u591a\u3002\u56e0\u4e3a\u5b58\u50a8\u8fc7\u7a0b\u662f\u9884\u7f16\u8bd1\u7684\uff0c\u5728\u9996\u6b21\u8fd0\u884c\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u67e5\u8be2\u4f18\u5316\u5668\u5bf9\u5176\u8fdb\u884c\u5206\u6790\u3001\u4f18\u5316\uff0c\u5e76\u7ed9\u51fa\u6700\u7ec8\u88ab\u5b58\u5728\u7cfb\u7edf\u8868\u4e2d\u7684\u6267\u884c\u8ba1\u5212\u3002\u800c\u6279\u5904\u7406\u7684Transaction- SQL \u8bed\u53e5\u5728\u6bcf\u6b21\u8fd0\u884c\u65f6\u90fd\u8981\u8fdb\u884c\u7f16\u8bd1\u548c\u4f18\u5316\uff0c\u56e0\u6b64\u901f\u5ea6\u76f8\u5bf9\u8981\u6162\u4e00\u4e9b\u3002<\/p>\n<p>     \uff083\uff09 \u5b58\u50a8\u8fc7\u7a0b\u80fd\u591f\u51cf\u5c11\u7f51\u7edc\u6d41\u91cf<\/p>\n<p>     \u5bf9\u4e8e\u540c\u4e00\u4e2a\u9488\u5bf9\u6570\u636e\u6570\u636e\u5e93\u5bf9\u8c61\u7684\u64cd\u4f5c\uff08\u5982\u67e5\u8be2\u3001\u4fee\u6539\uff09\uff0c\u5982\u679c\u8fd9\u4e00\u64cd\u4f5c\u6240\u6d89\u53ca\u5230\u7684 Transaction-SQL \u8bed\u53e5\u88ab\u7ec4\u7ec7\u6210\u4e00\u5b58\u50a8\u8fc7\u7a0b\uff0c\u90a3\u4e48\u5f53\u5728\u5ba2\u6237\u8ba1\u7b97\u673a\u4e0a\u8c03\u7528\u8be5\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u7f51\u7edc\u4e2d\u4f20\u9001\u7684\u53ea\u662f\u8be5\u8c03\u7528\u8bed\u53e5\uff0c\u5426\u5219\u5c06\u662f\u591a\u6761SQL \u8bed\u53e5\uff0c\u4ece\u800c\u5927\u5927\u589e\u52a0\u4e86\u7f51\u7edc\u6d41\u91cf\uff0c\u964d\u4f4e\u7f51\u7edc\u8d1f\u8f7d\u3002<\/p>\n<p>     \uff084\uff09 \u5b58\u50a8\u8fc7\u7a0b\u53ef\u88ab\u4f5c\u4e3a\u4e00\u79cd\u5b89\u5168\u673a\u5236\u6765\u5145\u5206\u5229\u7528<\/p>\n<p>     \u7cfb\u7edf\u7ba1\u7406\u5458\u901a\u8fc7\u5bf9\u6267\u884c\u67d0\u4e00\u5b58\u50a8\u8fc7\u7a0b\u7684\u6743\u9650\u8fdb\u884c\u9650\u5236\uff0c\u4ece\u800c\u80fd\u591f\u5b9e\u73b0\u5bf9\u76f8\u5e94\u7684\u6570\u636e\u8bbf\u95ee\u6743\u9650\u7684\u9650\u5236\uff0c\u907f\u514d\u975e\u6388\u6743\u7528\u6237\u5bf9\u6570\u636e\u7684\u8bbf\u95ee\uff0c\u4fdd\u8bc1\u6570\u636e\u7684\u5b89\u5168\u3002\uff08\u6211\u4eec\u5c06\u572814 \u7ae0\u201cSQLServer \u7684\u7528\u6237\u548c\u5b89\u5168\u6027\u7ba1\u7406\u201d\u4e2d\u5bf9\u5b58\u50a8\u8fc7\u7a0b\u7684\u8fd9\u4e00\u5e94\u7528\u4f5c\u66f4\u4e3a\u6e05\u6670\u7684\u4ecb\u7ecd\uff09<\/p>\n<p>     \u6ce8\u610f\uff1a\u5b58\u50a8\u8fc7\u7a0b\u867d\u7136\u65e2\u6709\u53c2\u6570\u53c8\u6709\u8fd4\u56de\u503c\uff0c\u4f46\u662f\u5b83\u4e0e\u51fd\u6570\u4e0d\u540c\u3002\u5b58\u50a8\u8fc7\u7a0b\u7684\u8fd4\u56de\u503c\u53ea\u662f\u6307\u660e\u6267\u884c\u662f\u5426\u6210\u529f\uff0c\u5e76\u4e14\u5b83\u4e0d\u80fd\u50cf\u51fd\u6570\u90a3\u6837\u88ab\u76f4\u63a5\u8c03\u7528\uff0c\u4e5f\u5c31\u662f\u5728\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u5728\u5b58\u50a8\u8fc7\u7a0b\u540d\u5b57\u524d\u4e00\u5b9a\u8981\u6709EXEC\u4fdd\u7559\u5b57\u3002 <\/p>\n<p><b><span style=\"font-size:12pt\">2.SQL\u5b58\u50a8\u8fc7\u7a0b\u521b\u5efa<\/span><\/b><\/p>\n<p>\u3000\u3000\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5b58\u50a8\u8fc7\u7a0b\u662f\u4fdd\u5b58\u8d77\u6765\u7684\u53ef\u4ee5\u63a5\u53d7\u548c\u8fd4\u56de\u7528\u6237\u63d0\u4f9b\u7684\u53c2\u6570\u7684 Transact-SQL \u8bed\u53e5\u7684\u96c6\u5408\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u8fc7\u7a0b\u4f9b\u6c38\u4e45\u4f7f\u7528\uff0c\u6216\u5728\u4e00\u4e2a\u4f1a\u8bdd\u4e2d\u4e34\u65f6\u4f7f\u7528\uff08\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\uff09\uff0c\u6216\u5728\u6240\u6709\u4f1a\u8bdd\u4e2d\u4e34\u65f6\u4f7f\u7528\uff08\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\uff09\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u4e5f\u53ef\u4ee5\u521b\u5efa\u5728 Microsoft? SQL Server? \u542f\u52a8\u65f6\u81ea\u52a8\u8fd0\u884c\u7684\u5b58\u50a8\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/><b>\u8bed\u6cd5<\/b><\/p>\n<blockquote><p>\u3000\u3000CREATE PROC [ EDURE ] procedure_name [ ; number ]<br \/>\u3000\u3000\u3000\u3000[ { @parameter data_type }<br \/>\u3000\u3000\u3000\u3000\u3000\u3000[ VARYING ] [ = default ] [ OUTPUT ]<br \/>\u3000\u3000\u3000\u3000] [ ,&#8230;n ] <br \/>\u3000\u3000<br \/>\u3000\u3000[ WITH<br \/>\u3000\u3000\u3000\u3000{ RECOMPILE | ENCRYPTION | RECOMPILE , ENCRYPTION } ] <br \/>\u3000\u3000<br \/>\u3000\u3000[ FOR REPLICATION ] <br \/>\u3000\u3000<br \/>\u3000\u3000AS sql_statement [ &#8230;n ]<\/p><\/blockquote>\n<p><b>\u53c2\u6570<\/b><\/p>\n<p>\u3000\u3000procedure_name<br \/>\u3000\u3000<br \/>      \u65b0\u5b58\u50a8\u8fc7\u7a0b\u7684\u540d\u79f0\u3002\u8fc7\u7a0b\u540d\u5fc5\u987b\u7b26\u5408\u6807\u8bc6\u7b26\u89c4\u5219\uff0c\u4e14\u5bf9\u4e8e\u6570\u636e\u5e93\u53ca\u5176\u6240\u6709\u8005\u5fc5\u987b\u552f\u4e00\u3002<br \/>\u3000\u3000\u8981\u521b\u5efa\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u5728 procedure_name \u524d\u9762\u52a0\u4e00\u4e2a\u7f16\u53f7\u7b26 (#procedure_name)\uff0c\u8981\u521b\u5efa\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\uff0c\u53ef\u4ee5\u5728 procedure_name \u524d\u9762\u52a0\u4e24\u4e2a\u7f16\u53f7\u7b26 (##procedure_name)\u3002\u5b8c\u6574\u7684\u540d\u79f0\uff08\u5305\u62ec # \u6216 ##\uff09\u4e0d\u80fd\u8d85\u8fc7 128 \u4e2a\u5b57\u7b26\u3002\u6307\u5b9a\u8fc7\u7a0b\u6240\u6709\u8005\u7684\u540d\u79f0\u662f\u53ef\u9009\u7684\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000;number<br \/>\u3000\u3000<br \/>\u3000\u3000\u662f\u53ef\u9009\u7684\u6574\u6570\uff0c\u7528\u6765\u5bf9\u540c\u540d\u7684\u8fc7\u7a0b\u5206\u7ec4\uff0c\u4ee5\u4fbf\u7528\u4e00\u6761 DROP PROCEDURE \u8bed\u53e5\u5373\u53ef\u5c06\u540c\u7ec4\u7684\u8fc7\u7a0b\u4e00\u8d77\u9664\u53bb\u3002\u4f8b\u5982\uff0c\u540d\u4e3a orders \u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u7684\u8fc7\u7a0b\u53ef\u4ee5\u547d\u540d\u4e3a orderproc;1\u3001orderproc;2 \u7b49\u3002DROP PROCEDURE orderproc \u8bed\u53e5\u5c06\u9664\u53bb\u6574\u4e2a\u7ec4\u3002\u5982\u679c\u540d\u79f0\u4e2d\u5305\u542b\u5b9a\u754c\u6807\u8bc6\u7b26\uff0c\u5219\u6570\u5b57\u4e0d\u5e94\u5305\u542b\u5728\u6807\u8bc6\u7b26\u4e2d\uff0c\u53ea\u5e94\u5728 procedure_name \u524d\u540e\u4f7f\u7528\u9002\u5f53\u7684\u5b9a\u754c\u7b26\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000@parameter<br \/>\u3000\u3000<br \/>\u3000\u3000\u8fc7\u7a0b\u4e2d\u7684\u53c2\u6570\u3002\u5728 CREATE PROCEDURE \u8bed\u53e5\u4e2d\u53ef\u4ee5\u58f0\u660e\u4e00\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u3002\u7528\u6237\u5fc5\u987b\u5728\u6267\u884c\u8fc7\u7a0b\u65f6\u63d0\u4f9b\u6bcf\u4e2a\u6240\u58f0\u660e\u53c2\u6570\u7684\u503c\uff08\u9664\u975e\u5b9a\u4e49\u4e86\u8be5\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\uff09\u3002\u5b58\u50a8\u8fc7\u7a0b\u6700\u591a\u53ef\u4ee5\u6709 2.100 \u4e2a\u53c2\u6570\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u4f7f\u7528 @ \u7b26\u53f7\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u5b57\u7b26\u6765\u6307\u5b9a\u53c2\u6570\u540d\u79f0\u3002\u53c2\u6570\u540d\u79f0\u5fc5\u987b\u7b26\u5408\u6807\u8bc6\u7b26\u7684\u89c4\u5219\u3002\u6bcf\u4e2a\u8fc7\u7a0b\u7684\u53c2\u6570\u4ec5\u7528\u4e8e\u8be5\u8fc7\u7a0b\u672c\u8eab\uff1b\u76f8\u540c\u7684\u53c2\u6570\u540d\u79f0\u53ef\u4ee5\u7528\u5728\u5176\u5b83\u8fc7\u7a0b\u4e2d\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53c2\u6570\u53ea\u80fd\u4ee3\u66ff\u5e38\u91cf\uff0c\u800c\u4e0d\u80fd\u7528\u4e8e\u4ee3\u66ff\u8868\u540d\u3001\u5217\u540d\u6216\u5176\u5b83\u6570\u636e\u5e93\u5bf9\u8c61\u7684\u540d\u79f0\u3002<br \/>\u3000\u3000data_type<br \/>\u3000\u3000<br \/>\u3000\u3000\u53c2\u6570\u7684\u6570\u636e\u7c7b\u578b\u3002\u6240\u6709\u6570\u636e\u7c7b\u578b\uff08\u5305\u62ec text\u3001ntext \u548c image\uff09\u5747\u53ef\u4ee5\u7528\u4f5c\u5b58\u50a8\u8fc7\u7a0b\u7684\u53c2\u6570\u3002\u4e0d\u8fc7\uff0ccursor \u6570\u636e\u7c7b\u578b\u53ea\u80fd\u7528\u4e8e OUTPUT \u53c2\u6570\u3002\u5982\u679c\u6307\u5b9a\u7684\u6570\u636e\u7c7b\u578b\u4e3a cursor\uff0c\u4e5f\u5fc5\u987b\u540c\u65f6\u6307\u5b9a VARYING \u548c OUTPUT \u5173\u952e\u5b57\u3002<\/p>\n<p>\u3000\u3000\u8bf4\u660e\u3000\u5bf9\u4e8e\u53ef\u4ee5\u662f cursor \u6570\u636e\u7c7b\u578b\u7684\u8f93\u51fa\u53c2\u6570\uff0c\u6ca1\u6709\u6700\u5927\u6570\u76ee\u7684\u9650\u5236\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000VARYING<br \/>\u3000\u3000<br \/>\u3000\u3000\u6307\u5b9a\u4f5c\u4e3a\u8f93\u51fa\u53c2\u6570\u652f\u6301\u7684\u7ed3\u679c\u96c6\uff08\u7531\u5b58\u50a8\u8fc7\u7a0b\u52a8\u6001\u6784\u9020\uff0c\u5185\u5bb9\u53ef\u4ee5\u53d8\u5316\uff09\u3002\u4ec5\u9002\u7528\u4e8e\u6e38\u6807\u53c2\u6570\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<\/p>\n<p>default<br \/>\u3000\u3000<br \/>\u3000\u3000\u53c2\u6570\u7684\u9ed8\u8ba4\u503c\u3002\u5982\u679c\u5b9a\u4e49\u4e86\u9ed8\u8ba4\u503c\uff0c\u4e0d\u5fc5\u6307\u5b9a\u8be5\u53c2\u6570\u7684\u503c\u5373\u53ef\u6267\u884c\u8fc7\u7a0b\u3002\u9ed8\u8ba4\u503c\u5fc5\u987b\u662f\u5e38\u91cf\u6216 NULL\u3002\u5982\u679c\u8fc7\u7a0b\u5c06\u5bf9\u8be5\u53c2\u6570\u4f7f\u7528 LIKE \u5173\u952e\u5b57\uff0c\u90a3\u4e48\u9ed8\u8ba4\u503c\u4e2d\u53ef\u4ee5\u5305\u542b\u901a\u914d\u7b26\uff08%\u3001_\u3001[] \u548c [^]\uff09\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000OUTPUT<br \/>\u3000\u3000<br \/>\u3000\u3000\u8868\u660e\u53c2\u6570\u662f\u8fd4\u56de\u53c2\u6570\u3002\u8be5\u9009\u9879\u7684\u503c\u53ef\u4ee5\u8fd4\u56de\u7ed9 EXEC[UTE]\u3002\u4f7f\u7528 OUTPUT \u53c2\u6570\u53ef\u5c06\u4fe1\u606f\u8fd4\u56de\u7ed9\u8c03\u7528\u8fc7\u7a0b\u3002Text\u3001ntext \u548c image \u53c2\u6570\u53ef\u7528\u4f5c OUTPUT \u53c2\u6570\u3002\u4f7f\u7528 OUTPUT \u5173\u952e\u5b57\u7684\u8f93\u51fa\u53c2\u6570\u53ef\u4ee5\u662f\u6e38\u6807\u5360\u4f4d\u7b26\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000n<br \/>\u3000\u3000<br \/>\u3000\u3000\u8868\u793a\u6700\u591a\u53ef\u4ee5\u6307\u5b9a 2.100 \u4e2a\u53c2\u6570\u7684\u5360\u4f4d\u7b26\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000{RECOMPILE | ENCRYPTION | RECOMPILE, ENCRYPTION}<br \/>\u3000\u3000<br \/>\u3000\u3000RECOMPILE \u8868\u660e SQL Server \u4e0d\u4f1a\u7f13\u5b58\u8be5\u8fc7\u7a0b\u7684\u8ba1\u5212\uff0c\u8be5\u8fc7\u7a0b\u5c06\u5728\u8fd0\u884c\u65f6\u91cd\u65b0\u7f16\u8bd1\u3002\u5728\u4f7f\u7528\u975e\u5178\u578b\u503c\u6216\u4e34\u65f6\u503c\u800c\u4e0d\u5e0c\u671b\u8986\u76d6\u7f13\u5b58\u5728\u5185\u5b58\u4e2d\u7684\u6267\u884c\u8ba1\u5212\u65f6\uff0c\u8bf7\u4f7f\u7528 RECOMPILE \u9009\u9879\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000ENCRYPTION \u8868\u793a SQL Server \u52a0\u5bc6 syscomments \u8868\u4e2d\u5305\u542b CREATE PROCEDURE \u8bed\u53e5\u6587\u672c\u7684\u6761\u76ee\u3002\u4f7f\u7528 ENCRYPTION \u53ef\u9632\u6b62\u5c06\u8fc7\u7a0b\u4f5c\u4e3a SQL Server \u590d\u5236\u7684\u4e00\u90e8\u5206\u53d1\u5e03\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000\u5728\u5347\u7ea7\u8fc7\u7a0b\u4e2d\uff0cSQL Server \u5229\u7528\u5b58\u50a8\u5728 syscomments \u4e2d\u7684\u52a0\u5bc6\u6ce8\u91ca\u6765\u91cd\u65b0\u521b\u5efa\u52a0\u5bc6\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000FOR REPLICATION<br \/>\u3000\u3000<br \/>\u3000\u3000\u6307\u5b9a\u4e0d\u80fd\u5728\u8ba2\u9605\u670d\u52a1\u5668\u4e0a\u6267\u884c\u4e3a\u590d\u5236\u521b\u5efa\u7684\u5b58\u50a8\u8fc7\u7a0b\u3002.\u4f7f\u7528 FOR REPLICATION \u9009\u9879\u521b\u5efa\u7684\u5b58\u50a8\u8fc7\u7a0b\u53ef\u7528\u4f5c\u5b58\u50a8\u8fc7\u7a0b\u7b5b\u9009\uff0c\u4e14\u53ea\u80fd\u5728\u590d\u5236\u8fc7\u7a0b\u4e2d\u6267\u884c\u3002\u672c\u9009\u9879\u4e0d\u80fd\u548c WITH RECOMPILE \u9009\u9879\u4e00\u8d77\u4f7f\u7528\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000AS<br \/>\u3000\u3000<br \/>\u3000\u3000\u6307\u5b9a\u8fc7\u7a0b\u8981\u6267\u884c\u7684\u64cd\u4f5c\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000sql_statement<br \/>\u3000\u3000<br \/>\u3000\u3000\u8fc7\u7a0b\u4e2d\u8981\u5305\u542b\u7684\u4efb\u610f\u6570\u76ee\u548c\u7c7b\u578b\u7684 Transact-SQL \u8bed\u53e5\u3002\u4f46\u6709\u4e00\u4e9b\u9650\u5236\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000n<br \/>\u3000\u3000<br \/>\u3000\u3000\u662f\u8868\u793a\u6b64\u8fc7\u7a0b\u53ef\u4ee5\u5305\u542b\u591a\u6761 Transact-SQL \u8bed\u53e5\u7684\u5360\u4f4d\u7b26\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u6ce8\u91ca<br \/>\u3000\u3000\u5b58\u50a8\u8fc7\u7a0b\u7684\u6700\u5927\u5927\u5c0f\u4e3a 128 MB\u3002<br \/>\u7528\u6237\u5b9a\u4e49\u7684\u5b58\u50a8\u8fc7\u7a0b\u53ea\u80fd\u5728\u5f53\u524d\u6570\u636e\u5e93\u4e2d\u521b\u5efa\uff08\u4e34\u65f6\u8fc7\u7a0b\u9664\u5916\uff0c\u4e34\u65f6\u8fc7\u7a0b\u603b\u662f\u5728 tempdb \u4e2d\u521b\u5efa\uff09\u3002\u5728\u5355\u4e2a\u6279\u5904\u7406\u4e2d\uff0cCREATE PROCEDURE \u8bed\u53e5\u4e0d\u80fd\u4e0e\u5176\u5b83 Transact-SQL \u8bed\u53e5\u7ec4\u5408\u4f7f\u7528\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u53c2\u6570\u53ef\u4e3a\u7a7a\u3002\u5982\u679c\u4f20\u9012 NULL \u53c2\u6570\u503c\u5e76\u4e14\u8be5\u53c2\u6570\u5728 CREATE \u6216 ALTER TABLE \u8bed\u53e5\u4e2d\u4f7f\u7528\uff0c\u800c\u8be5\u8bed\u53e5\u4e2d\u5f15\u7528\u7684\u5217\u53c8\u4e0d\u5141\u8bb8\u4f7f\u7528 NULL\uff0c\u5219 SQL Server \u4f1a\u4ea7\u751f\u4e00\u6761\u9519\u8bef\u4fe1\u606f\u3002\u4e3a\u4e86\u9632\u6b62\u5411\u4e0d\u5141\u8bb8\u4f7f\u7528 NULL \u7684\u5217\u4f20\u9012 NULL \u53c2\u6570\u503c\uff0c\u5e94\u5411\u8fc7\u7a0b\u4e2d\u6dfb\u52a0\u7f16\u7a0b\u903b\u8f91\u6216\u4e3a\u8be5\u5217\u4f7f\u7528\u9ed8\u8ba4\u503c\uff08\u4f7f\u7528 CREATE \u6216 ALTER TABLE \u7684 DEFAULT \u5173\u952e\u5b57)\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5efa\u8bae\u5728\u5b58\u50a8\u8fc7\u7a0b\u7684\u4efb\u4f55 CREATE TABLE \u6216 ALTER TABLE \u8bed\u53e5\u4e2d\u90fd\u4e3a\u6bcf\u5217\u663e\u5f0f\u6307\u5b9a NULL \u6216 NOT NULL\uff0c\u4f8b\u5982\u5728\u521b\u5efa\u4e34\u65f6\u8868\u65f6\u3002ANSI_DFLT_ON \u548c ANSI_DFLT_OFF \u9009\u9879\u63a7\u5236 SQL Server \u4e3a\u5217\u6307\u6d3e NULL \u6216 NOT NULL \u7279\u6027\u7684\u65b9\u5f0f\uff08\u5982\u679c\u5728 CREATE TABLE \u6216 ALTER TABLE \u8bed\u53e5\u4e2d\u6ca1\u6709\u6307\u5b9a\u7684\u8bdd\uff09\u3002\u5982\u679c\u67d0\u4e2a\u8fde\u63a5\u6267\u884c\u7684\u5b58\u50a8\u8fc7\u7a0b\u5bf9\u8fd9\u4e9b\u9009\u9879\u7684\u8bbe\u7f6e\u4e0e\u521b\u5efa\u8be5\u8fc7\u7a0b\u7684\u8fde\u63a5\u7684\u8bbe\u7f6e\u4e0d\u540c\uff0c\u5219\u4e3a\u7b2c\u4e8c\u4e2a\u8fde\u63a5\u521b\u5efa\u7684\u8868\u5217\u53ef\u80fd\u4f1a\u6709\u4e0d\u540c\u7684\u4e3a\u7a7a\u6027\uff0c\u5e76\u4e14\u8868\u73b0\u51fa\u4e0d\u540c\u7684\u884c\u4e3a\u65b9\u5f0f\u3002\u5982\u679c\u4e3a\u6bcf\u4e2a\u5217\u663e\u5f0f\u58f0\u660e\u4e86 NULL \u6216 NOT NULL\uff0c\u90a3\u4e48\u5c06\u5bf9\u6240\u6709\u6267\u884c\u8be5\u5b58\u50a8\u8fc7\u7a0b\u7684\u8fde\u63a5\u4f7f\u7528\u76f8\u540c\u7684\u4e3a\u7a7a\u6027\u521b\u5efa\u4e34\u65f6\u8868\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5728\u521b\u5efa\u6216\u66f4\u6539\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0cSQL Server \u5c06\u4fdd\u5b58 SET QUOTED_IDENTIFIER \u548c SET ANSI_NULLS \u7684\u8bbe\u7f6e\u3002\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u65f6\uff0c\u5c06\u4f7f\u7528\u8fd9\u4e9b\u539f\u59cb\u8bbe\u7f6e\u3002\u56e0\u6b64\uff0c\u6240\u6709\u5ba2\u6237\u7aef\u4f1a\u8bdd\u7684 SET QUOTED_IDENTIFIER \u548c SET ANSI_NULLS \u8bbe\u7f6e\u5728\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u65f6\u90fd\u5c06\u88ab\u5ffd\u7565\u3002\u5728\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u51fa\u73b0\u7684 SET QUOTED_IDENTIFIER \u548c SET ANSI_NULLS \u8bed\u53e5\u4e0d\u5f71\u54cd\u5b58\u50a8\u8fc7\u7a0b\u7684\u529f\u80fd\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5176\u5b83 SET \u9009\u9879\uff08\u4f8b\u5982 SET ARITHABORT\u3001SET ANSI_WARNINGS \u6216 SET ANSI_PADDINGS\uff09\u5728\u521b\u5efa\u6216\u66f4\u6539\u5b58\u50a8\u8fc7\u7a0b\u65f6\u4e0d\u4fdd\u5b58\u3002\u5982\u679c\u5b58\u50a8\u8fc7\u7a0b\u7684\u903b\u8f91\u53d6\u51b3\u4e8e\u7279\u5b9a\u7684\u8bbe\u7f6e\uff0c\u5e94\u5728\u8fc7\u7a0b\u5f00\u5934\u6dfb\u52a0\u4e00\u6761 SET \u8bed\u53e5\uff0c\u4ee5\u786e\u4fdd\u8bbe\u7f6e\u6b63\u786e\u3002\u4ece\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u6267\u884c SET \u8bed\u53e5\u65f6\uff0c\u8be5\u8bbe\u7f6e\u53ea\u5728\u5b58\u50a8\u8fc7\u7a0b\u5b8c\u6210\u4e4b\u524d\u6709\u6548\u3002\u4e4b\u540e\uff0c\u8bbe\u7f6e\u5c06\u6062\u590d\u4e3a\u8c03\u7528\u5b58\u50a8\u8fc7\u7a0b\u65f6\u7684\u503c\u3002\u8fd9\u4f7f\u4e2a\u522b\u7684\u5ba2\u6237\u7aef\u53ef\u4ee5\u8bbe\u7f6e\u6240\u9700\u7684\u9009\u9879\uff0c\u800c\u4e0d\u4f1a\u5f71\u54cd\u5b58\u50a8\u8fc7\u7a0b\u7684\u903b\u8f91\u3002<br \/>\u3000\u3000<\/p>\n<p>\u3000\u3000\u8bf4\u660e\u3000SQL Server \u662f\u5c06\u7a7a\u5b57\u7b26\u4e32\u89e3\u91ca\u4e3a\u5355\u4e2a\u7a7a\u683c\u8fd8\u662f\u89e3\u91ca\u4e3a\u771f\u6b63\u7684\u7a7a\u5b57\u7b26\u4e32\uff0c\u7531\u517c\u5bb9\u7ea7\u522b\u8bbe\u7f6e\u63a7\u5236\u3002<br \/>\u3000\u3000\u5982\u679c\u517c\u5bb9\u7ea7\u522b\u5c0f\u4e8e\u6216\u7b49\u4e8e 65\uff0cSQL Server \u5c31\u5c06\u7a7a\u5b57\u7b26\u4e32\u89e3\u91ca\u4e3a\u5355\u4e2a\u7a7a\u683c\u3002<br \/>\u3000\u3000\u5982\u679c\u517c\u5bb9\u7ea7\u522b\u7b49\u4e8e 70\uff0c\u5219 SQL Server \u5c06\u7a7a\u5b57\u7b26\u4e32\u89e3\u91ca\u4e3a\u7a7a\u5b57\u7b26\u4e32\u3002<br \/>\u3000\u3000\u83b7\u5f97\u6709\u5173\u5b58\u50a8\u8fc7\u7a0b\u7684\u4fe1\u606f<br \/>\u3000\u3000\u82e5\u8981\u663e\u793a\u7528\u6765\u521b\u5efa\u8fc7\u7a0b\u7684\u6587\u672c\uff0c\u8bf7\u5728\u8fc7\u7a0b\u6240\u5728\u7684\u6570\u636e\u5e93\u4e2d\u6267\u884c sp_helptext\uff0c\u5e76\u4f7f\u7528\u8fc7\u7a0b\u540d\u4f5c\u4e3a\u53c2\u6570\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000\u4f7f\u7528 ENCRYPTION \u9009\u9879\u521b\u5efa\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e0d\u80fd\u4f7f\u7528 sp_helptext \u67e5\u770b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u82e5\u8981\u663e\u793a\u6709\u5173\u8fc7\u7a0b\u5f15\u7528\u7684\u5bf9\u8c61\u7684\u62a5\u8868\uff0c\u8bf7\u4f7f\u7528 sp_depends\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u82e5\u8981\u4e3a\u8fc7\u7a0b\u91cd\u547d\u540d\uff0c\u8bf7\u4f7f\u7528 sp_rename\u3002 <\/p>\n<p><b>\u5f15\u7528\u5bf9\u8c61<\/b><\/p>\n<p>\u3000\u3000SQL Server \u5141\u8bb8\u521b\u5efa\u7684\u5b58\u50a8\u8fc7\u7a0b\u5f15\u7528\u5c1a\u4e0d\u5b58\u5728\u7684\u5bf9\u8c61\u3002\u5728\u521b\u5efa\u65f6\uff0c\u53ea\u8fdb\u884c\u8bed\u6cd5\u68c0\u67e5\u3002\u6267\u884c\u65f6\uff0c\u5982\u679c\u9ad8\u901f\u7f13\u5b58\u4e2d\u5c1a\u65e0\u6709\u6548\u7684\u8ba1\u5212\uff0c\u5219\u7f16\u8bd1\u5b58\u50a8\u8fc7\u7a0b\u4ee5\u751f\u6210\u6267\u884c\u8ba1\u5212\u3002\u53ea\u6709\u5728\u7f16\u8bd1\u8fc7\u7a0b\u4e2d\u624d\u89e3\u6790\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u5f15\u7528\u7684\u6240\u6709\u5bf9\u8c61\u3002\u56e0\u6b64\uff0c\u5982\u679c\u8bed\u6cd5\u6b63\u786e\u7684\u5b58\u50a8\u8fc7\u7a0b\u5f15\u7528\u4e86\u4e0d\u5b58\u5728\u7684\u5bf9\u8c61\uff0c\u5219\u4ecd\u53ef\u4ee5\u6210\u529f\u521b\u5efa\uff0c\u4f46\u5728\u8fd0\u884c\u65f6\u5c06\u5931\u8d25\uff0c\u56e0\u4e3a\u6240\u5f15\u7528\u7684\u5bf9\u8c61\u4e0d\u5b58\u5728\u3002<br \/>\u3000\u3000\u5ef6\u8fdf\u540d\u79f0\u89e3\u6790\u548c\u517c\u5bb9\u7ea7\u522b<br \/>\u3000\u3000SQL Server \u5141\u8bb8 Transact-SQL \u5b58\u50a8\u8fc7\u7a0b\u5728\u521b\u5efa\u65f6\u5f15\u7528\u4e0d\u5b58\u5728\u7684\u8868\u3002\u8fd9\u79cd\u80fd\u529b\u79f0\u4e3a\u5ef6\u8fdf\u540d\u79f0\u89e3\u6790\u3002\u4e0d\u8fc7\uff0c\u5982\u679c Transact-SQL \u5b58\u50a8\u8fc7\u7a0b\u5f15\u7528\u4e86\u8be5\u5b58\u50a8\u8fc7\u7a0b\u4e2d\u5b9a\u4e49\u7684\u8868\uff0c\u800c\u517c\u5bb9\u7ea7\u522b\u8bbe\u7f6e\uff08\u901a\u8fc7\u6267\u884c sp_dbcmptlevel \u6765\u8bbe\u7f6e\uff09\u4e3a 65\uff0c\u5219\u5728\u521b\u5efa\u65f6\u4f1a\u53d1\u51fa\u8b66\u544a\u4fe1\u606f\u3002\u800c\u5982\u679c\u5728\u8fd0\u884c\u65f6\u6240\u5f15\u7528\u7684\u8868\u4e0d\u5b58\u5728\uff0c\u5c06\u8fd4\u56de\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n<p><b>\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b<\/b><\/p>\n<p>\u3000\u3000\u6210\u529f\u6267\u884c CREATE PROCEDURE \u8bed\u53e5\u540e\uff0c\u8fc7\u7a0b\u540d\u79f0\u5c06\u5b58\u50a8\u5728 sysobjects \u7cfb\u7edf\u8868\u4e2d\uff0c\u800c CREATE PROCEDURE \u8bed\u53e5\u7684\u6587\u672c\u5c06\u5b58\u50a8\u5728 syscomments \u4e2d\u3002\u7b2c\u4e00\u6b21\u6267\u884c\u65f6\uff0c\u5c06\u7f16\u8bd1\u8be5\u8fc7\u7a0b\u4ee5\u786e\u5b9a\u68c0\u7d22\u6570\u636e\u7684\u6700\u4f73\u8bbf\u95ee\u8ba1\u5212\u3002<br \/>\u3000\u3000<br \/><b>\u4f7f\u7528 cursor \u6570\u636e\u7c7b\u578b\u7684\u53c2\u6570<\/b><\/p>\n<p>\u3000\u3000\u5b58\u50a8\u8fc7\u7a0b\u53ea\u80fd\u5c06 cursor \u6570\u636e\u7c7b\u578b\u7528\u4e8e OUTPUT \u53c2\u6570\u3002\u5982\u679c\u4e3a\u67d0\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86 cursor \u6570\u636e\u7c7b\u578b\uff0c\u4e5f\u5fc5\u987b\u6307\u5b9a VARYING \u548c OUTPUT \u53c2\u6570\u3002\u5982\u679c\u4e3a\u67d0\u4e2a\u53c2\u6570\u6307\u5b9a\u4e86 VARYING \u5173\u952e\u5b57\uff0c\u5219\u6570\u636e\u7c7b\u578b\u5fc5\u987b\u662f cursor\uff0c\u5e76\u4e14\u5fc5\u987b\u6307\u5b9a OUTPUT \u5173\u952e\u5b57\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000cursor \u6570\u636e\u7c7b\u578b\u4e0d\u80fd\u901a\u8fc7\u6570\u636e\u5e93 API\uff08\u4f8b\u5982 OLE DB\u3001ODBC\u3001ADO \u548c DB-Library\uff09\u7ed1\u5b9a\u5230\u5e94\u7528\u7a0b\u5e8f\u53d8\u91cf\u4e0a\u3002\u56e0\u4e3a\u5fc5\u987b\u5148\u7ed1\u5b9a OUTPUT \u53c2\u6570\uff0c\u5e94\u7528\u7a0b\u5e8f\u624d\u53ef\u4ee5\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\uff0c\u6240\u4ee5\u5e26\u6709 cursor OUTPUT \u53c2\u6570\u7684\u5b58\u50a8\u8fc7\u7a0b\u4e0d\u80fd\u901a\u8fc7\u6570\u636e\u5e93 API \u8c03\u7528\u3002\u53ea\u6709\u5c06 cursor OUTPUT \u53d8\u91cf\u8d4b\u503c\u7ed9 Transact-SQL \u5c40\u90e8 cursor \u53d8\u91cf\u65f6\uff0c\u624d\u53ef\u4ee5\u901a\u8fc7 Transact-SQL \u6279\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u8c03\u7528\u8fd9\u4e9b\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000Cursor \u8f93\u51fa\u53c2\u6570<br \/>\u3000\u3000\u5728\u6267\u884c\u8fc7\u7a0b\u65f6\uff0c\u4ee5\u4e0b\u89c4\u5219\u9002\u7528\u4e8e cursor \u8f93\u51fa\u53c2\u6570\uff1a <br \/>\u3000\u3000<br \/>\u3000\u3000\u5bf9\u4e8e\u53ea\u8fdb\u6e38\u6807\uff0c\u6e38\u6807\u7684\u7ed3\u679c\u96c6\u4e2d\u8fd4\u56de\u7684\u884c\u53ea\u662f\u90a3\u4e9b\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u7ed3\u675f\u65f6\u5904\u4e8e\u6216\u8d85\u51fa\u6e38\u6807\u4f4d\u7f6e\u7684\u884c\uff0c\u4f8b\u5982\uff1a <br \/>\u3000\u3000\u5728\u8fc7\u7a0b\u4e2d\u7684\u540d\u4e3a RS \u7684 100 \u884c\u7ed3\u679c\u96c6\u4e0a\u6253\u5f00\u4e00\u4e2a\u975e\u6eda\u52a8\u6e38\u6807\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u8fc7\u7a0b\u63d0\u53d6\u7ed3\u679c\u96c6 RS \u7684\u5934 5 \u884c\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u8fc7\u7a0b\u8fd4\u56de\u5230\u5176\u8c03\u7528\u8005\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u8fd4\u56de\u5230\u8c03\u7528\u8005\u7684\u7ed3\u679c\u96c6 RS \u7531 RS \u7684\u7b2c 6 \u5230 100 \u884c\u7ec4\u6210\uff0c\u8c03\u7528\u8005\u4e2d\u7684\u6e38\u6807\u5904\u4e8e RS \u7684\u7b2c\u4e00\u884c\u4e4b\u524d\u3002 <br \/>\u3000\u3000\u5bf9\u4e8e\u53ea\u8fdb\u6e38\u6807\uff0c\u5982\u679c\u5b58\u50a8\u8fc7\u7a0b\u5b8c\u6210\u540e\uff0c\u6e38\u6807\u4f4d\u4e8e\u7b2c\u4e00\u884c\u7684\u524d\u9762\uff0c\u5219\u6574\u4e2a\u7ed3\u679c\u96c6\u5c06\u8fd4\u56de\u7ed9\u8c03\u7528\u6279<\/p>\n<p>\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u3002\u8fd4\u56de\u65f6\uff0c\u6e38\u6807\u5c06\u4f4d\u4e8e\u7b2c\u4e00\u884c\u7684\u524d\u9762\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u5bf9\u4e8e\u53ea\u8fdb\u6e38\u6807\uff0c\u5982\u679c\u5b58\u50a8\u8fc7\u7a0b\u5b8c\u6210\u540e\uff0c\u6e38\u6807\u7684\u4f4d\u7f6e\u8d85\u51fa\u6700\u540e\u4e00\u884c\u7684\u7ed3\u5c3e\uff0c\u5219\u4e3a\u8c03\u7528\u6279\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u8fd4\u56de\u7a7a\u7ed3\u679c\u96c6\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000\u7a7a\u7ed3\u679c\u96c6\u4e0e\u7a7a\u503c\u4e0d\u540c\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5bf9\u4e8e\u53ef\u6eda\u52a8\u6e38\u6807\uff0c\u5728\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u7ed3\u675f\u65f6\uff0c\u7ed3\u679c\u96c6\u4e2d\u7684\u6240\u6709\u884c\u5747\u4f1a\u8fd4\u56de\u7ed9\u8c03\u7528\u6279\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u3002\u8fd4\u56de\u65f6\uff0c\u6e38\u6807\u4fdd\u7559\u5728\u8fc7\u7a0b\u4e2d\u6700\u540e\u4e00\u6b21\u6267\u884c\u63d0\u53d6\u65f6\u7684\u4f4d\u7f6e\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5bf9\u4e8e\u4efb\u610f\u7c7b\u578b\u7684\u6e38\u6807\uff0c\u5982\u679c\u6e38\u6807\u5173\u95ed\uff0c\u5219\u5c06\u7a7a\u503c\u4f20\u9012\u56de\u8c03\u7528\u6279\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u3002\u5982\u679c\u5c06\u6e38\u6807\u6307\u6d3e\u7ed9\u4e00\u4e2a\u53c2\u6570\uff0c\u4f46\u8be5\u6e38\u6807\u4ece\u672a\u6253\u5f00\u8fc7\uff0c\u4e5f\u4f1a\u51fa\u73b0\u8fd9\u79cd\u60c5\u51b5\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000\u5173\u95ed\u72b6\u6001\u53ea\u6709\u5728\u8fd4\u56de\u65f6\u624d\u6709\u5f71\u54cd\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u5728\u8fc7\u7a0b\u4e2d\u5173\u95ed\u6e38\u6807\uff0c\u7a0d\u540e\u518d\u6253\u5f00\u6e38\u6807\uff0c\u7136\u540e\u5c06\u8be5\u6e38\u6807\u7684\u7ed3\u679c\u96c6\u8fd4\u56de\u7ed9\u8c03\u7528\u6279\u5904\u7406\u3001\u5b58\u50a8\u8fc7\u7a0b\u6216\u89e6\u53d1\u5668\u3002<br \/>\u3000\u3000<br \/><b>\u4e34\u65f6\u5b58\u50a8\u8fc7\u7a0b<\/b><\/p>\n<p>\u3000\u3000SQL Server \u652f\u6301\u4e24\u79cd\u4e34\u65f6\u8fc7\u7a0b\uff1a\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\u548c\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\u3002\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\u53ea\u80fd\u7531\u521b\u5efa\u8be5\u8fc7\u7a0b\u7684\u8fde\u63a5\u4f7f\u7528\u3002\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\u5219\u53ef\u7531\u6240\u6709\u8fde\u63a5\u4f7f\u7528\u3002\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\u5728\u5f53\u524d\u4f1a\u8bdd\u7ed3\u675f\u65f6\u81ea\u52a8\u9664\u53bb\u3002\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\u5728\u4f7f\u7528\u8be5\u8fc7\u7a0b\u7684\u6700\u540e\u4e00\u4e2a\u4f1a\u8bdd\u7ed3\u675f\u65f6\u9664\u53bb\u3002\u901a\u5e38\u662f\u5728\u521b\u5efa\u8be5\u8fc7\u7a0b\u7684\u4f1a\u8bdd\u7ed3\u675f\u65f6\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u4e34\u65f6\u8fc7\u7a0b\u7528 # \u548c ## \u547d\u540d\uff0c\u53ef\u4ee5\u7531\u4efb\u4f55\u7528\u6237\u521b\u5efa\u3002\u521b\u5efa\u8fc7\u7a0b\u540e\uff0c\u5c40\u90e8\u8fc7\u7a0b\u7684\u6240\u6709\u8005\u662f\u552f\u4e00\u53ef\u4ee5\u4f7f\u7528\u8be5\u8fc7\u7a0b\u7684\u7528\u6237\u3002\u6267\u884c\u5c40\u90e8\u4e34\u65f6\u8fc7\u7a0b\u7684\u6743\u9650\u4e0d\u80fd\u6388\u4e88\u5176\u4ed6\u7528\u6237\u3002\u5982\u679c\u521b\u5efa\u4e86\u5168\u5c40\u4e34\u65f6\u8fc7\u7a0b\uff0c\u5219\u6240\u6709\u7528\u6237\u5747\u53ef\u4ee5\u8bbf\u95ee\u8be5\u8fc7\u7a0b\uff0c\u6743\u9650\u4e0d\u80fd\u663e\u5f0f\u5e9f\u9664\u3002\u53ea\u6709\u5728 tempdb \u6570\u636e\u5e93\u4e2d\u5177\u6709\u663e\u5f0f CREATE PROCEDURE \u6743\u9650\u7684\u7528\u6237\uff0c\u624d\u53ef\u4ee5\u5728\u8be5\u6570\u636e\u5e93\u4e2d\u663e\u5f0f\u521b\u5efa\u4e34\u65f6\u8fc7\u7a0b\uff08\u4e0d\u4f7f\u7528\u7f16\u53f7\u7b26\u547d\u540d\uff09\u3002\u53ef\u4ee5\u6388\u4e88\u6216\u5e9f\u9664\u8fd9\u4e9b\u8fc7\u7a0b\u4e2d\u7684\u6743\u9650\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u8bf4\u660e\u3000\u9891\u7e41\u4f7f\u7528\u4e34\u65f6\u5b58\u50a8\u8fc7\u7a0b\u4f1a\u5728 tempdb \u4e2d\u7684\u7cfb\u7edf\u8868\u4e0a\u4ea7\u751f\u4e89\u7528\uff0c\u4ece\u800c\u5bf9\u6027\u80fd\u4ea7\u751f\u8d1f\u9762\u5f71\u54cd\u3002\u5efa\u8bae\u4f7f\u7528 sp_executesql \u4ee3\u66ff\u3002sp_executesql \u4e0d\u5728\u7cfb\u7edf\u8868\u4e2d\u5b58\u50a8\u6570\u636e\uff0c\u56e0\u6b64\u53ef\u4ee5\u907f\u514d\u8fd9\u4e00\u95ee\u9898\u3002<\/p>\n<p><b>\u81ea\u52a8\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b<\/b><\/p>\n<p>\u3000\u3000SQL Server \u542f\u52a8\u65f6\u53ef\u4ee5\u81ea\u52a8\u6267\u884c\u4e00\u4e2a\u6216\u591a\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u3002\u8fd9\u4e9b\u5b58\u50a8\u8fc7\u7a0b\u5fc5\u987b\u7531\u7cfb\u7edf\u7ba1\u7406\u5458\u521b\u5efa\uff0c\u5e76\u5728 sysadmin \u56fa\u5b9a\u670d\u52a1\u5668\u89d2\u8272\u4e0b\u4f5c\u4e3a\u540e\u53f0\u8fc7\u7a0b\u6267\u884c\u3002\u8fd9\u4e9b\u8fc7\u7a0b\u4e0d\u80fd\u6709\u4efb\u4f55\u8f93\u5165\u53c2\u6570\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u5bf9\u542f\u52a8\u8fc7\u7a0b\u7684\u6570\u76ee\u6ca1\u6709\u9650\u5236\uff0c\u4f46\u662f\u8981\u6ce8\u610f\uff0c\u6bcf\u4e2a\u542f\u52a8\u8fc7\u7a0b\u5728\u6267\u884c\u65f6\u90fd\u4f1a\u5360\u7528\u4e00\u4e2a\u8fde\u63a5\u3002\u5982\u679c\u5fc5\u987b\u5728\u542f\u52a8\u65f6\u6267\u884c\u591a\u4e2a\u8fc7\u7a0b\uff0c\u4f46\u4e0d\u9700\u8981\u5e76\u884c\u6267\u884c\uff0c\u5219\u53ef\u4ee5\u6307\u5b9a\u4e00\u4e2a\u8fc7\u7a0b\u4f5c\u4e3a\u542f\u52a8\u8fc7\u7a0b\uff0c\u8ba9\u8be5\u8fc7\u7a0b\u8c03\u7528\u5176\u5b83\u8fc7\u7a0b\u3002\u8fd9\u6837\u5c31\u53ea\u5360\u7528\u4e00\u4e2a\u8fde\u63a5\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u5728\u542f\u52a8\u65f6\u6062\u590d\u4e86\u6700\u540e\u4e00\u4e2a\u6570\u636e\u5e93\u540e\uff0c\u5373\u5f00\u59cb\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u3002\u82e5\u8981\u8df3\u8fc7\u8fd9\u4e9b\u5b58\u50a8\u8fc7\u7a0b\u7684\u6267\u884c\uff0c\u8bf7\u5c06\u542f\u52a8\u53c2\u6570\u6307\u5b9a\u4e3a\u8ddf\u8e2a\u6807\u8bb0 4022\u3002\u5982\u679c\u4ee5\u6700\u4f4e\u914d\u7f6e\u542f\u52a8 SQL Server\uff08\u4f7f\u7528 -f \u6807\u8bb0\uff09\uff0c\u5219\u542f\u52a8\u5b58\u50a8\u8fc7\u7a0b\u4e5f\u4e0d\u4f1a\u6267\u884c\u3002<br \/>\u3000\u3000\u82e5\u8981\u521b\u5efa\u542f\u52a8\u5b58\u50a8\u8fc7\u7a0b\uff0c\u5fc5\u987b\u4f5c\u4e3a sysadmin \u56fa\u5b9a\u670d\u52a1\u5668\u89d2\u8272\u7684\u6210\u5458\u767b\u5f55\uff0c\u5e76\u5728 master \u6570\u636e\u5e93\u4e2d\u521b\u5efa\u5b58\u50a8\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u4f7f\u7528 sp_procoption \u53ef\u4ee5\uff1a <br \/>\u3000\u3000<br \/>\u3000\u3000\u5c06\u73b0\u6709\u5b58\u50a8\u8fc7\u7a0b\u6307\u5b9a\u4e3a\u542f\u52a8\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u505c\u6b62\u5728 SQL Server \u542f\u52a8\u65f6\u6267\u884c\u8fc7\u7a0b\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000<br \/>\u3000\u3000\u67e5\u770b SQL Server \u542f\u52a8\u65f6\u6267\u884c\u7684\u6240\u6709\u8fc7\u7a0b\u7684\u5217\u8868\u3002 <br \/>\u3000\u3000\u5b58\u50a8\u8fc7\u7a0b\u5d4c\u5957<br \/>\u3000\u3000\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u5d4c\u5957\uff0c\u5373\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u8c03\u7528\u53e6\u4e00\u4e2a\u5b58\u50a8\u8fc7\u7a0b\u3002\u5728\u88ab\u8c03\u7528\u8fc7\u7a0b\u5f00\u59cb\u6267\u884c\u65f6\uff0c\u5d4c\u5957\u7ea7\u5c06\u589e\u52a0\uff0c\u5728\u88ab\u8c03\u7528\u8fc7\u7a0b\u6267\u884c\u7ed3\u675f\u540e\uff0c\u5d4c\u5957\u7ea7\u5c06\u51cf\u5c11\u3002\u5982\u679c\u8d85\u51fa\u6700\u5927\u7684\u5d4c\u5957\u7ea7\uff0c\u4f1a\u4f7f\u6574\u4e2a\u8c03\u7528\u8fc7\u7a0b\u94fe\u5931\u8d25\u3002\u53ef\u7528 @@NESTLEVEL \u51fd\u6570\u8fd4\u56de\u5f53\u524d\u7684\u5d4c\u5957\u7ea7\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000\u82e5\u8981\u4f30\u8ba1\u7f16\u8bd1\u540e\u7684\u5b58\u50a8\u8fc7\u7a0b\u5927\u5c0f\uff0c\u8bf7\u4f7f\u7528\u4e0b\u5217\u6027\u80fd\u76d1\u89c6\u8ba1\u6570\u5668\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000  <br \/>\u3000\u3000* \u5404\u79cd\u5206\u7c7b\u7684\u9ad8\u901f\u7f13\u5b58\u5bf9\u8c61\u5747\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b\u8ba1\u6570\u5668\uff0c\u5305\u62ec\u7279\u6b8a sql\u3001\u51c6\u5907 sql\u3001\u8fc7\u7a0b\u3001\u89e6\u53d1\u5668\u7b49\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000sql_statement \u9650\u5236<br \/>\u3000\u3000\u9664\u4e86 SET SHOWPLAN_TEXT \u548c SET SHOWPLAN_ALL \u4e4b\u5916\uff08\u8fd9\u4e24\u4e2a\u8bed\u53e5\u5fc5\u987b\u662f\u6279\u5904\u7406\u4e2d\u4ec5\u6709\u7684\u8bed\u53e5\uff09\uff0c\u4efb\u4f55 SET \u8bed\u53e5\u5747\u53ef\u4ee5\u5728\u5b58\u50a8\u8fc7\u7a0b\u5185\u90e8\u6307\u5b9a\u3002\u6240\u9009\u62e9\u7684 SET \u9009\u9879\u5728\u5b58\u50a8\u8fc7\u7a0b\u6267\u884c\u8fc7\u7a0b\u4e2d\u6709\u6548\uff0c\u4e4b\u540e\u6062\u590d\u4e3a\u539f\u6765\u7684\u8bbe\u7f6e\u3002 <br \/>\u3000\u3000<br \/>\u3000\u3000\u5982\u679c\u5176\u4ed6\u7528\u6237\u8981\u4f7f\u7528\u67d0\u4e2a\u5b58\u50a8\u8fc7\u7a0b\uff0c\u90a3\u4e48\u5728\u8be5\u5b58\u50a8\u8fc7\u7a0b\u5185\u90e8\uff0c\u4e00\u4e9b\u8bed\u53e5\u4f7f\u7528\u7684\u5bf9\u8c61\u540d\u5fc5\u987b\u4f7f\u7528\u5bf9\u8c61\u6240\u6709\u8005\u7684\u540d\u79f0\u9650\u5b9a\u3002\u8fd9\u4e9b\u8bed\u53e5\u5305\u62ec\uff1a <br \/>\u3000\u3000<br \/>\u3000\u3000ALTER TABLE<br \/>\u3000\u3000<br \/>\u3000\u3000CREATE INDEX<br \/>\u3000\u3000<br \/>\u3000\u3000CREATE TABLE<br \/>\u3000\u3000<br \/>\u3000\u3000\u6240\u6709 DBCC \u8bed\u53e5<br \/>\u3000\u3000<br \/>\u3000\u3000DROP TABLE<br \/>\u3000\u3000<br \/>\u3000\u3000DROP INDEX<br \/>\u3000\u3000<br \/>\u3000\u3000TRUNCATE TABLE<br \/>\u3000\u3000<br \/>\u3000\u3000UPDATE STATISTICS <br \/>\u3000\u3000\u6743\u9650<br \/>\u3000\u3000CREATE PROCEDURE \u7684\u6743\u9650\u9ed8\u8ba4\u6388\u4e88 sysadmin \u56fa\u5b9a\u670d\u52a1\u5668\u89d2\u8272\u6210\u5458\u548c db_owner \u548c db_ddladmin \u56fa\u5b9a\u6570\u636e\u5e93\u89d2\u8272\u6210\u5458\u3002sysadmin \u56fa\u5b9a\u670d\u52a1\u5668\u89d2\u8272\u6210\u5458\u548c db_owner \u56fa\u5b9a\u6570\u636e\u5e93\u89d2\u8272\u6210\u5458\u53ef\u4ee5\u5c06 CREATE PROCEDURE \u6743\u9650\u8f6c\u8ba9\u7ed9\u5176\u4ed6\u7528\u6237\u3002\u6267\u884c\u5b58\u50a8\u8fc7\u7a0b\u7684\u6743\u9650\u6388\u4e88\u8fc7\u7a0b\u7684\u6240\u6709\u8005\uff0c\u8be5\u6240\u6709\u8005\u53ef\u4ee5\u4e3a\u5176\u5b83\u6570\u636e\u5e93\u7528\u6237\u8bbe\u7f6e\u6267\u884c\u6743\u9650\u3002<br \/>\u793a\u4f8b<br \/>\u3000\u3000A. \u4f7f\u7528\u5e26\u6709\u590d\u6742 SELECT \u8bed\u53e5\u7684\u7b80\u5355\u8fc7\u7a0b<br \/>\u3000\u3000\u4e0b\u9762\u7684\u5b58\u50a8\u8fc7\u7a0b\u4ece\u56db\u4e2a\u8868\u7684\u8054\u63a5\u4e2d\u8fd4\u56de\u6240\u6709\u4f5c\u8005\uff08\u63d0\u4f9b\u4e86\u59d3\u540d\uff09\u3001\u51fa\u7248\u7684\u4e66\u7c4d\u4ee5\u53ca\u51fa\u7248\u793e\u3002\u8be5\u5b58\u50a8\u8fc7\u7a0b\u4e0d\u4f7f\u7528\u4efb\u4f55\u53c2\u6570\u3002<br \/>\u3000\u3000<br \/>\u3000\u3000USE pubs<br \/>\u3000\u3000IF EXISTS (SELECT name FROM sysobjects <br \/>\u3000\u3000\u3000\u3000\u3000\u3000 WHERE name = \\&#39;au_info_all\\&#39; AND type = \\&#39;P\\&#39;)<br \/>\u3000\u3000\u3000 DROP PROCEDURE au_info_all<br \/>\u3000\u3000GO<br \/>\u3000\u3000CREATE PROCEDURE au_info_all<br \/>\u3000\u3000AS<br \/>\u3000\u3000SELECT au_lname, au_fname, title, pub_name<br \/>\u3000\u3000\u3000 FROM authors a INNER JOIN titleauthor ta<br \/>\u3000\u3000\u3000\u3000\u3000ON a.au_id = ta.au_id INNER JOIN titles t<br \/>\u3000\u3000\u3000\u3000\u3000ON t.title_id = ta.title_id INNER JOIN publishers p<br \/>\u3000\u3000\u3000\u3000\u3000ON t.pub_id = p.pub_id<br \/>\u3000\u3000GO<br \/>\u3000\u3000<br \/>\u3000\u3000au_info_all \u5b58\u50a8\u8fc7\u7a0b\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u6267\u884c\uff1a<br \/>\u3000\u3000<br \/>\u3000\u3000EXECUTE au_info_all<br \/>\u3000\u3000&#8211; Or<br \/>\u3000\u3000EXEC au_info_all<br \/>\u3000\u3000<br \/>\u3000\u3000\u5982\u679c\u8be5\u8fc7\u7a0b\u662f\u6279\u5904\u7406\u4e2d\u7684\u7b2c\u4e00\u6761\u8bed\u53e5\uff0c\u5219\u53ef\u4f7f\u7528\uff1a<br \/>\u3000\u3000<br \/>\u3000\u3000au_info_all<\/p>\n","protected":false},"excerpt":{"rendered":"<p>1.SQL\u5b58\u50a8\u8fc7\u7a0b\u6982\u8ff0 \u5728\u5927\u578b\u6570\u636e\u5e93\u7cfb\u7edf\u4e2d\uff0c\u5b58\u50a8\u8fc7\u7a0b\u548c\u89e6\u53d1\u5668\u5177\u6709\u5f88\u91cd\u8981\u7684\u4f5c\u7528\u3002\u65e0 &hellip; <a href=\"https:\/\/www.cnmiss.cn\/?p=52\">\u7ee7\u7eed\u9605\u8bfb <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[23],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-xxbj","tag-mssql"],"_links":{"self":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=52"}],"version-history":[{"count":0,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=\/wp\/v2\/posts\/52\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cnmiss.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}