{"id":812,"date":"2025-01-11T00:33:45","date_gmt":"2025-01-10T16:33:45","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=812"},"modified":"2025-01-11T00:33:45","modified_gmt":"2025-01-10T16:33:45","slug":"%e5%9c%a8-sql-server-%e4%b8%ad%ef%bc%8c%e6%80%8e%e6%a0%b7%e7%a1%ae%e4%bf%9d%e5%9c%a8%e4%ba%8b%e5%8a%a1%e5%a4%b1%e8%b4%a5%e6%97%b6%e8%83%bd%e6%ad%a3%e7%a1%ae%e5%9b%9e%e6%bb%9a%e5%b9%b6%e5%a4%84","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/01\/11\/%e5%9c%a8-sql-server-%e4%b8%ad%ef%bc%8c%e6%80%8e%e6%a0%b7%e7%a1%ae%e4%bf%9d%e5%9c%a8%e4%ba%8b%e5%8a%a1%e5%a4%b1%e8%b4%a5%e6%97%b6%e8%83%bd%e6%ad%a3%e7%a1%ae%e5%9b%9e%e6%bb%9a%e5%b9%b6%e5%a4%84\/","title":{"rendered":"\u5728 SQL Server \u4e2d\uff0c\u600e\u6837\u786e\u4fdd\u5728\u4e8b\u52a1\u5931\u8d25\u65f6\u80fd\u6b63\u786e\u56de\u6eda\u5e76\u5904\u7406\u76f8\u5173\u9519\u8bef"},"content":{"rendered":"\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p class=\"wp-block-paragraph\">SQL Server \u4e2d\u7684\u4e8b\u52a1\u56de\u6eda\u673a\u5236\u6d89\u53ca\u591a\u65b9\u9762\u7684\u5904\u7406\uff0c\u81ea\u52a8\u56de\u6eda\u7684\u573a\u666f\u4e0d\u4ec5\u5305\u62ec\u7cfb\u7edf\u9519\u8bef\u3001\u6b7b\u9501\u548c\u8d85\u65f6\u7b49\u60c5\u51b5\uff0c\u8fd8\u5305\u62ec\u6570\u636e\u5e93\u6062\u590d\u6a21\u5f0f\u3001\u8d44\u6e90\u4e0d\u8db3\u548c\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u7b49\u56e0\u7d20\u3002\u7406\u89e3\u8fd9\u4e9b\u673a\u5236\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\uff0c\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\uff0c\u5e76\u5408\u7406\u5904\u7406\u6570\u636e\u5e93\u4e2d\u7684\u4e8b\u52a1\u56de\u6eda\u3002QL Server \u7684\u81ea\u52a8\u4e8b\u52a1\u56de\u6eda\u901a\u5e38\u7531\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\u89e6\u53d1\uff1a<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">1. <strong>\u7cfb\u7edf\u9519\u8bef<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53 SQL Server \u9047\u5230\u7cfb\u7edf\u9519\u8bef\u6216\u4e25\u91cd\u9519\u8bef\u65f6\uff0c\u4e8b\u52a1\u4f1a\u81ea\u52a8\u56de\u6eda\u3002\u8fd9\u4e9b\u9519\u8bef\u901a\u5e38\u662f\u7531\u4e8e\u786c\u4ef6\u6545\u969c\u3001\u6570\u636e\u5e93\u635f\u574f\u3001\u6b7b\u9501\u7b49\u539f\u56e0\u5f15\u8d77\u7684\u3002SQL Server \u4f1a\u786e\u4fdd\u6570\u636e\u7684\u4e00\u81f4\u6027\uff0c\u56e0\u6b64\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f1a\u81ea\u52a8\u56de\u6eda\u6240\u6709\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u4f8b\u5b50\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u786c\u4ef6\u6545\u969c\u5bfc\u81f4\u7684\u6570\u636e\u5e93\u5d29\u6e83\u3002<\/li>\n\n\n\n<li>SQL Server \u5d29\u6e83\u3002<\/li>\n\n\n\n<li>\u67d0\u4e9b\u7c7b\u578b\u7684\u4e25\u91cd\u9519\u8bef\uff08\u4f8b\u5982 824 \u9519\u8bef\uff0c\u8868\u793a\u78c1\u76d8 I\/O \u9519\u8bef\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">2. <strong>\u6b7b\u9501 (Deadlock)<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 SQL Server \u4e2d\uff0c\u5982\u679c\u53d1\u751f\u6b7b\u9501\uff0c\u5373\u4e24\u4e2a\u6216\u591a\u4e2a\u4e8b\u52a1\u5728\u7b49\u5f85\u5f7c\u6b64\u6301\u6709\u7684\u8d44\u6e90\u65f6\u65e0\u6cd5\u7ee7\u7eed\u6267\u884c\uff0cSQL Server \u4f1a\u81ea\u52a8\u9009\u62e9\u5176\u4e2d\u4e00\u4e2a\u4e8b\u52a1\u8fdb\u884c\u56de\u6eda\uff0c\u4ee5\u6253\u7834\u6b7b\u9501\u3002\u8fd9\u4e2a\u88ab\u56de\u6eda\u7684\u4e8b\u52a1\u4f1a\u4ea7\u751f\u4e00\u4e2a\u9519\u8bef\uff0c\u5e76\u4e14\u88ab\u7ec8\u6b62\u3002\u56de\u6eda\u7684\u4e8b\u52a1\u5c06\u91ca\u653e\u5b83\u6301\u6709\u7684\u8d44\u6e90\uff0c\u4ece\u800c\u5141\u8bb8\u5176\u4ed6\u4e8b\u52a1\u7ee7\u7eed\u6267\u884c\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u6b7b\u9501\u68c0\u6d4b<\/strong>\uff1aSQL Server \u6bcf\u9694\u4e00\u5b9a\u65f6\u95f4\u4f1a\u68c0\u6d4b\u6b7b\u9501\uff0c\u4e00\u65e6\u68c0\u6d4b\u5230\u6b7b\u9501\uff0c\u7cfb\u7edf\u4f1a\u56de\u6eda\u4e00\u4e2a\u4e8b\u52a1\u6765\u89e3\u51b3\u6b7b\u9501\u95ee\u9898\u3002<\/li>\n\n\n\n<li><strong>\u9519\u8bef\u4fe1\u606f<\/strong>\uff1a\u5f53\u6b7b\u9501\u53d1\u751f\u65f6\uff0c\u88ab\u56de\u6eda\u7684\u4e8b\u52a1\u4f1a\u63a5\u6536\u5230 <code>Error 1205<\/code>\uff08\u6b7b\u9501\u9519\u8bef\uff09\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">3. <strong>\u4e8b\u52a1\u8d85\u65f6<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u5728 SQL Server \u4e2d\u8bbe\u7f6e\u4e86\u4e8b\u52a1\u8d85\u65f6\uff08\u4f8b\u5982\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\u8bbe\u7f6e\u4e86\u8d85\u65f6\u65f6\u95f4\uff09\uff0c\u5f53\u4e8b\u52a1\u5728\u89c4\u5b9a\u65f6\u95f4\u5185\u6ca1\u6709\u5b8c\u6210\uff0cSQL Server \u53ef\u80fd\u4f1a\u81ea\u52a8\u56de\u6eda\u4e8b\u52a1\u3002\u8fd9\u901a\u5e38\u662f\u7531\u4e8e\u4e8b\u52a1\u6267\u884c\u65f6\u95f4\u8fc7\u957f\u6216\u963b\u585e\u5bfc\u81f4\u7684\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4e8b\u52a1\u8d85\u65f6\u9519\u8bef<\/strong>\uff1a\u5e94\u7528\u7a0b\u5e8f\u6216\u8005 SQL Server \u5ba2\u6237\u7aef\uff08\u5982 SQL Server Management Studio\uff09\u4f1a\u56e0\u8d85\u65f6\u9519\u8bef\u7ec8\u6b62\u4e8b\u52a1\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">4. <strong>\u663e\u5f0f\u56de\u6eda<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4e8b\u52a1\u4e2d\u53d1\u751f\u4e86\u9519\u8bef\uff0c\u7a0b\u5e8f\u5458\u53ef\u4ee5\u663e\u5f0f\u8c03\u7528 <code>ROLLBACK TRANSACTION<\/code> \u6765\u56de\u6eda\u4e8b\u52a1\u3002\u867d\u7136\u8fd9\u901a\u5e38\u662f\u624b\u52a8\u64cd\u4f5c\uff0c\u4f46\u53ef\u4ee5\u770b\u4f5c\u662f\u4e00\u4e2a\u81ea\u52a8\u56de\u6eda\u7684\u201c\u89e6\u53d1\u5668\u201d\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>BEGIN TRANSACTION;\n-- \u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\nIF (\u67d0\u4e2a\u6761\u4ef6) \n    ROLLBACK TRANSACTION;\n-- \u5426\u5219 COMMIT\nCOMMIT TRANSACTION;<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">5. <strong>\u89e6\u53d1\u5668\u9519\u8bef<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u89e6\u53d1\u5668\u4e2d\u7684\u64cd\u4f5c\u5931\u8d25\u65f6\uff0c\u5982\u679c\u89e6\u53d1\u5668\u8fd0\u884c\u7684\u4e0a\u4e0b\u6587\u662f\u4e8b\u52a1\u7684\u4e00\u90e8\u5206\uff0c\u90a3\u4e48\u8be5\u4e8b\u52a1\u5c06\u88ab\u56de\u6eda\u3002\u6b64\u65f6\uff0c\u89e6\u53d1\u5668\u7684\u9519\u8bef\u4f1a\u5bfc\u81f4\u6574\u4e2a\u4e8b\u52a1\u7684\u56de\u6eda\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. <strong>\u9519\u8bef\u7ea7\u522b\u4e25\u91cd\u7684 SQL \u9519\u8bef<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u4e2d\u6709\u4e0d\u540c\u7ea7\u522b\u7684\u9519\u8bef\uff08\u4ece 1 \u5230 25\uff09\u3002\u7ea7\u522b\u4e3a 11 \u5230 19 \u7684\u9519\u8bef\u901a\u5e38\u4e0d\u4f1a\u81ea\u52a8\u56de\u6eda\u4e8b\u52a1\uff0c\u800c\u662f\u4f1a\u7ec8\u6b62\u5f53\u524d\u8bed\u53e5\u6216\u6279\u5904\u7406\u3002\u5bf9\u4e8e\u7ea7\u522b\u4e3a 20 \u6216\u66f4\u9ad8\u7684\u9519\u8bef\uff0cSQL Server \u4f1a\u81ea\u52a8\u56de\u6eda\u5f53\u524d\u4e8b\u52a1\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">\u5e38\u89c1\u4e25\u91cd\u9519\u8bef\uff1a<\/h4>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9519\u8bef\u7ea7\u522b 20\uff08\u5982\u7f51\u7edc\u95ee\u9898\uff09\u901a\u5e38\u4f1a\u5bfc\u81f4\u8fde\u63a5\u4e22\u5931\uff0c\u5e76\u5bfc\u81f4\u4e8b\u52a1\u56de\u6eda\u3002<\/li>\n\n\n\n<li>\u9519\u8bef\u7ea7\u522b 25 \u8868\u793a\u5185\u90e8\u9519\u8bef\u6216\u4e25\u91cd\u9519\u8bef\uff0c\u4e8b\u52a1\u4f1a\u88ab\u81ea\u52a8\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">7. <strong>\u4e8b\u52a1\u5185\u5b58\u4e0d\u8db3<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c SQL Server \u5185\u5b58\u4e0d\u8db3\u4ee5\u652f\u6301\u4e8b\u52a1\u7684\u6267\u884c\uff0c\u4e8b\u52a1\u53ef\u80fd\u4f1a\u56e0\u4e3a\u5185\u5b58\u4e0d\u8db3\u88ab\u5f3a\u5236\u56de\u6eda\u3002SQL Server \u4f1a\u5c1d\u8bd5\u5206\u914d\u8db3\u591f\u7684\u8d44\u6e90\u6765\u5b8c\u6210\u4e8b\u52a1\uff0c\u4f46\u5982\u679c\u6ca1\u6709\u8db3\u591f\u7684\u5185\u5b58\u6216\u78c1\u76d8\u7a7a\u95f4\uff0c\u4e8b\u52a1\u4f1a\u88ab\u56de\u6eda\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u81ea\u52a8\u56de\u6eda\u7684\u5177\u4f53\u5904\u7406\u65b9\u5f0f<\/h3>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>\u5f02\u5e38\u5904\u7406<\/strong>\uff1a<\/li>\n<\/ol>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SQL Server \u901a\u8fc7 <code>TRY...CATCH<\/code> \u5757\u6765\u5904\u7406\u9519\u8bef\u3002\u5982\u679c\u5728 <code>TRY<\/code> \u5757\u4e2d\u53d1\u751f\u9519\u8bef\uff0c\u63a7\u5236\u5c06\u8f6c\u5230 <code>CATCH<\/code> \u5757\u3002\u53ef\u4ee5\u5728 <code>CATCH<\/code> \u5757\u4e2d\u6dfb\u52a0\u56de\u6eda\u4ee3\u7801\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>   BEGIN TRY\n       BEGIN TRANSACTION;\n       -- \u6267\u884c\u4e00\u4e9b\u64cd\u4f5c\n       COMMIT TRANSACTION;\n   END TRY\n   BEGIN CATCH\n       ROLLBACK TRANSACTION;\n       -- \u9519\u8bef\u4fe1\u606f\u5904\u7406\n       PRINT ERROR_MESSAGE();\n   END CATCH;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u65b9\u5f0f\u80fd\u786e\u4fdd\u5728\u53d1\u751f\u9519\u8bef\u65f6\u4e8b\u52a1\u4f1a\u56de\u6eda\uff0c\u5e76\u5904\u7406\u9519\u8bef\u4fe1\u606f\u3002<\/p>\n\n\n\n<ol start=\"2\" class=\"wp-block-list\">\n<li><strong>\u81ea\u52a8\u63d0\u4ea4\u6a21\u5f0f<\/strong>\uff1a<br>\u5982\u679c\u672a\u663e\u5f0f\u4f7f\u7528\u4e8b\u52a1\uff08\u5373\u4e0d\u4f7f\u7528 <code>BEGIN TRANSACTION<\/code>\uff09\uff0cSQL Server \u4f1a\u5728\u6bcf\u4e2a SQL \u8bed\u53e5\u6267\u884c\u540e\u81ea\u52a8\u63d0\u4ea4\u4e8b\u52a1\u3002\u5982\u679c\u9047\u5230\u9519\u8bef\uff0cSQL Server \u4f1a\u81ea\u52a8\u56de\u6eda\u5f53\u524d\u8bed\u53e5\u4e2d\u7684\u90e8\u5206\uff08\u4f8b\u5982\u8fdd\u53cd\u7ea6\u675f\u7684\u63d2\u5165\u64cd\u4f5c\uff09\u3002<\/li>\n\n\n\n<li><\/li>\n<\/ol>\n\n\n\n<h3 class=\"wp-block-heading\">8. <strong>\u6570\u636e\u5e93\u6062\u590d\u6a21\u5f0f<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u63d0\u4f9b\u4e09\u79cd\u6570\u636e\u5e93\u6062\u590d\u6a21\u5f0f\uff1a\u7b80\u5355\uff08Simple\uff09\u3001\u5b8c\u5168\uff08Full\uff09\u548c\u5927\u5bb9\u91cf\u65e5\u5fd7\uff08Bulk-Logged\uff09\u3002\u5728\u8fd9\u4e9b\u6a21\u5f0f\u4e0b\uff0c\u4e8b\u52a1\u65e5\u5fd7\u7684\u7ba1\u7406\u65b9\u5f0f\u4e0d\u540c\uff0c\u53ef\u80fd\u5f71\u54cd\u4e8b\u52a1\u56de\u6eda\u7684\u884c\u4e3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u5b8c\u5168\u6062\u590d\u6a21\u5f0f\uff08Full Recovery Mode\uff09<\/strong>\uff1a\u5728\u6b64\u6a21\u5f0f\u4e0b\uff0cSQL Server \u4f1a\u5c06\u6240\u6709\u6570\u636e\u5e93\u4e8b\u52a1\u8be6\u7ec6\u8bb0\u5f55\u5230\u65e5\u5fd7\u6587\u4ef6\u4e2d\uff0c\u5e76\u4e14\u53ef\u4ee5\u5728\u51fa\u73b0\u6545\u969c\u65f6\u6062\u590d\u5230\u67d0\u4e00\u7279\u5b9a\u65f6\u95f4\u70b9\u3002\u5982\u679c\u4e8b\u52a1\u6ca1\u6709\u6210\u529f\u63d0\u4ea4\uff0cSQL Server \u4f1a\u901a\u8fc7\u6062\u590d\u65e5\u5fd7\u6765\u56de\u6eda\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002<\/li>\n\n\n\n<li><strong>\u7b80\u5355\u6062\u590d\u6a21\u5f0f\uff08Simple Recovery Mode\uff09<\/strong>\uff1a\u6b64\u6a21\u5f0f\u4e0b\uff0cSQL Server \u4e0d\u4f1a\u8be6\u7ec6\u8bb0\u5f55\u4e8b\u52a1\u65e5\u5fd7\uff0c\u56e0\u6b64\uff0c\u4e8b\u52a1\u56de\u6eda\u7684\u80fd\u529b\u53d7\u5230\u9650\u5236\u3002\u4e00\u822c\u7528\u4e8e\u4e0d\u9700\u8981\u9ad8\u5b8c\u6574\u6027\u4fdd\u969c\u7684\u573a\u666f\uff08\u5982\u4e34\u65f6\u8868\u7684\u64cd\u4f5c\uff09\u3002<\/li>\n\n\n\n<li><strong>\u5927\u5bb9\u91cf\u65e5\u5fd7\u6a21\u5f0f\uff08Bulk-Logged Recovery Mode\uff09<\/strong>\uff1a\u4e3b\u8981\u7528\u4e8e\u9ad8\u6548\u6279\u91cf\u63d2\u5165\u64cd\u4f5c\uff0c\u4f46\u4ecd\u7136\u4fdd\u6301\u4e8b\u52a1\u65e5\u5fd7\u7684\u4e00\u5b9a\u7a0b\u5ea6\u8bb0\u5f55\u3002\u5982\u679c\u64cd\u4f5c\u5931\u8d25\uff0cSQL Server \u4f1a\u81ea\u52a8\u56de\u6eda\u6279\u91cf\u64cd\u4f5c\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">9. <strong>\u5f02\u6b65\u63d0\u4ea4\u4e8b\u52a1<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u9ad8\u8d1f\u8f7d\u573a\u666f\u4e0b\uff0cSQL Server \u652f\u6301 <strong>\u5f02\u6b65\u63d0\u4ea4\u4e8b\u52a1<\/strong>\uff0c\u901a\u8fc7\u8bbe\u7f6e <code>SET IMPLICIT_TRANSACTIONS<\/code> \u6216\u4f7f\u7528 <strong>\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/strong> \u63a7\u5236\u4e8b\u52a1\u63d0\u4ea4\u884c\u4e3a\u3002\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4e8b\u52a1\u53ef\u80fd\u6ca1\u6709\u540c\u6b65\u63d0\u4ea4\u6216\u56de\u6eda\uff0c\u8fd9\u79cd\u673a\u5236\u6709\u65f6\u53ef\u80fd\u4f1a\u5bfc\u81f4\u770b\u4f3c\u201c\u81ea\u52a8\u56de\u6eda\u201d\u7684\u60c5\u5f62\uff08\u4f8b\u5982\u4e8b\u52a1\u8d85\u65f6\u6216\u8fde\u63a5\u4e22\u5931\uff09\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f02\u6b65\u4e8b\u52a1\u63d0\u4ea4\u7684\u60c5\u51b5\uff1a\u5f53\u4e8b\u52a1\u5728\u4e0d\u7acb\u5373\u63d0\u4ea4\u7684\u60c5\u51b5\u4e0b\u4ecd\u4fdd\u6301\u6253\u5f00\u72b6\u6001\uff0c\u800c\u6570\u636e\u5e93\u53d1\u751f\u6545\u969c\u65f6\uff0c\u4e8b\u52a1\u9700\u8981\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">10. <strong>\u5ef6\u8fdf\u548c\u7f13\u5b58\u5f15\u53d1\u7684\u56de\u6eda<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 SQL Server \u4e2d\uff0c\u6709\u4e9b\u9519\u8bef\u5e76\u975e\u7acb\u5373\u4ea7\u751f\uff0c\u800c\u662f\u53d1\u751f\u5728\u4e8b\u52a1\u63d0\u4ea4\u65f6\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u7f51\u7edc\u4e2d\u65ad<\/strong>\uff1a\u5982\u679c\u5ba2\u6237\u7aef\u4e0e SQL Server \u4e4b\u95f4\u7684\u8fde\u63a5\u88ab\u610f\u5916\u4e2d\u65ad\uff0cSQL Server \u4f1a\u5728\u540e\u7aef\u56de\u6eda\u8be5\u4e8b\u52a1\uff0c\u5c24\u5176\u662f\u5982\u679c\u8be5\u4e8b\u52a1\u8fd8\u6ca1\u6709\u88ab\u63d0\u4ea4\u3002<\/li>\n\n\n\n<li><strong>\u8868\u9501\/\u884c\u9501<\/strong>\uff1a\u5f53\u5176\u4ed6\u4e8b\u52a1\u6301\u6709\u67d0\u4e9b\u9501\uff08\u5982 <code>X<\/code> \u9501\uff09\uff0c\u5e76\u4e14\u8fd9\u4e9b\u9501\u65e0\u6cd5\u91ca\u653e\u65f6\uff0c\u4e8b\u52a1\u53ef\u80fd\u5728\u7b49\u5f85\u9501\u91ca\u653e\u7684\u8fc7\u7a0b\u4e2d\u8d85\u65f6\uff0c\u6700\u7ec8\u5bfc\u81f4\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">11. <strong>\u81ea\u52a8\u56de\u6eda\u7684 SQL Server \u9519\u8bef\u4ee3\u7801<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u8fd4\u56de\u7684\u9519\u8bef\u4ee3\u7801\u4e0d\u4ec5\u662f\u5bfc\u81f4\u4e8b\u52a1\u56de\u6eda\u7684\u5173\u952e\uff0c\u8fd8\u53ef\u4ee5\u5e2e\u52a9\u7406\u89e3\u56de\u6eda\u7684\u539f\u56e0\u3002\u5e38\u89c1\u7684\u9519\u8bef\u4ee3\u7801\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>1205 (\u6b7b\u9501\u9519\u8bef)<\/strong>\uff1a\u5982\u524d\u6240\u8ff0\uff0c\u6b7b\u9501\u68c0\u6d4b\u4f1a\u5bfc\u81f4\u56de\u6eda\u5176\u4e2d\u4e00\u4e2a\u4e8b\u52a1\u3002<\/li>\n\n\n\n<li><strong>4000 &#8211; 4999<\/strong>\uff1a\u8fd9\u7c7b\u9519\u8bef\u901a\u5e38\u4e3a\u5e94\u7528\u7a0b\u5e8f\u9519\u8bef\uff0c\u53ef\u80fd\u89e6\u53d1\u4e8b\u52a1\u56de\u6eda\u3002<\/li>\n\n\n\n<li><strong>50000 &#8211; 59999<\/strong>\uff1a\u8fd9\u4e9b\u9519\u8bef\u901a\u5e38\u662f\u7531\u7528\u6237\u5b9a\u4e49\u7684\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u901a\u8fc7 <code>THROW<\/code> \u6216 <code>RAISEERROR<\/code> \u53d1\u51fa\u7684\u3002\u7528\u6237\u5b9a\u4e49\u7684\u9519\u8bef\u53ef\u80fd\u4f1a\u5bfc\u81f4\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">12. <strong>CLR \u96c6\u6210\u4e2d\u7684\u56de\u6eda<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u8fd8\u652f\u6301 .NET \u7f16\u5199\u7684 CLR\uff08\u516c\u5171\u8bed\u8a00\u8fd0\u884c\u65f6\uff09\u7a0b\u5e8f\u96c6\u3002\u5982\u679c\u5728 CLR \u7a0b\u5e8f\u96c6\u4e2d\u51fa\u73b0\u672a\u6355\u83b7\u7684\u5f02\u5e38\u6216\u9519\u8bef\uff0cSQL Server \u4f1a\u81ea\u52a8\u56de\u6eda\u4e8b\u52a1\u3002\u8fd9\u662f\u56e0\u4e3a CLR \u7a0b\u5e8f\u96c6\u7684\u6267\u884c\u4e5f\u9075\u5faa SQL Server \u7684\u4e8b\u52a1\u6a21\u578b\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. <strong>\u89e6\u53d1\u5668\u4e2d\u7684\u4e8b\u52a1\u56de\u6eda<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 SQL Server \u4e2d\uff0c\u89e6\u53d1\u5668\u6267\u884c\u65f6\u901a\u5e38\u4f1a\u5728\u5f53\u524d\u4e8b\u52a1\u4e2d\u8fd0\u884c\u3002\u5982\u679c\u89e6\u53d1\u5668\u629b\u51fa\u5f02\u5e38\u6216\u9047\u5230\u9519\u8bef\uff0cSQL Server \u4f1a\u56de\u6eda\u89e6\u53d1\u5668\u6240\u5728\u7684\u4e8b\u52a1\u3002\u6839\u636e\u89e6\u53d1\u5668\u7684\u903b\u8f91\u548c\u4e8b\u52a1\u8bbe\u7f6e\uff0cSQL Server \u53ef\u80fd\u4f1a\u56de\u6eda\u6574\u4e2a\u4e8b\u52a1\uff0c\u6216\u8005\u4ec5\u56de\u6eda\u89e6\u53d1\u5668\u672c\u8eab\u7684\u64cd\u4f5c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>-- \u89e6\u53d1\u5668\u793a\u4f8b\uff1a\u63d2\u5165\u6570\u636e\u65f6\u53d1\u751f\u9519\u8bef\uff0c\u56de\u6eda\u6574\u4e2a\u4e8b\u52a1\nCREATE TRIGGER trg_AfterInsert\nON Employees\nFOR INSERT\nAS\nBEGIN\n    IF EXISTS (SELECT * FROM inserted WHERE Salary &lt; 1000)\n    BEGIN\n        -- \u5982\u679c\u85aa\u6c34\u4f4e\u4e8e1000\uff0c\u629b\u51fa\u9519\u8bef\u5e76\u56de\u6eda\u6574\u4e2a\u4e8b\u52a1\n        RAISERROR('Salary cannot be less than 1000', 16, 1);\n        ROLLBACK TRANSACTION;\n    END\nEND<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">14. <strong>\u4e8b\u52a1\u65e5\u5fd7\u5907\u4efd\u4e0e\u6062\u590d<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6062\u590d\u6a21\u5f0f\u4e3a <strong>\u5b8c\u6574\u6062\u590d\u6a21\u5f0f<\/strong> \u7684\u60c5\u51b5\u4e0b\uff0c\u4e8b\u52a1\u65e5\u5fd7\u662f\u4e8b\u52a1\u56de\u6eda\u7684\u5173\u952e\u5de5\u5177\u3002\u4e8b\u52a1\u56de\u6eda\u64cd\u4f5c\u57fa\u4e8e\u4e8b\u52a1\u65e5\u5fd7\u5907\u4efd\u8fdb\u884c\u6062\u590d\u3002\u901a\u8fc7\u6062\u590d\u5230\u67d0\u4e2a\u65f6\u95f4\u70b9\uff0cSQL Server \u4f1a\u56de\u6eda\u6240\u6709\u672a\u63d0\u4ea4\u7684\u4e8b\u52a1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u5982\u679c\u67d0\u4e2a\u4e8b\u52a1\u672a\u6210\u529f\u63d0\u4ea4\u4e14\u6570\u636e\u5e93\u5d29\u6e83\uff0c\u53ef\u4ee5\u901a\u8fc7\u4e8b\u52a1\u65e5\u5fd7\u7684\u5907\u4efd\u6765\u6062\u590d\u8be5\u4e8b\u52a1\u7684\u72b6\u6001\uff0c\u56de\u6eda\u6240\u6709\u672a\u63d0\u4ea4\u7684\u90e8\u5206\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. <strong>\u8d44\u6e90\u4e0d\u8db3\u5f15\u8d77\u7684\u56de\u6eda<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u5728\u8d44\u6e90\u4e0d\u8db3\uff08\u5982\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\u3001\u5185\u5b58\u4e0d\u8db3\u3001I\/O \u64cd\u4f5c\u5931\u8d25\uff09\u65f6\uff0c\u53ef\u80fd\u4f1a\u5f3a\u5236\u56de\u6eda\u6b63\u5728\u6267\u884c\u7684\u4e8b\u52a1\u3002SQL Server \u4f1a\u5c1d\u8bd5\u4fdd\u6301\u6570\u636e\u7684\u4e00\u81f4\u6027\uff0c\u901a\u5e38\u4f1a\u53d1\u751f\u4ee5\u4e0b\u51e0\u79cd\u60c5\u51b5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3<\/strong>\uff1aSQL Server \u4f1a\u56de\u6eda\u5f53\u524d\u4e8b\u52a1\uff0c\u4ee5\u91ca\u653e\u5b58\u50a8\u7a7a\u95f4\u3002<\/li>\n\n\n\n<li><strong>\u5185\u5b58\u4e0d\u8db3<\/strong>\uff1a\u5982\u679c SQL Server \u65e0\u6cd5\u5206\u914d\u8db3\u591f\u7684\u5185\u5b58\u6765\u6267\u884c\u67d0\u4e2a\u67e5\u8be2\u6216\u64cd\u4f5c\uff0c\u4e8b\u52a1\u4f1a\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">16. <strong>\u81ea\u52a8\u56de\u6eda\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u63d0\u4f9b\u4e86\u4e0d\u540c\u7684\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\uff0c\u5176\u4e2d\u67d0\u4e9b\u7ea7\u522b\u53ef\u80fd\u4f1a\u5f71\u54cd\u56de\u6eda\u7684\u884c\u4e3a\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>READ UNCOMMITTED<\/strong>\uff1a\u5141\u8bb8\u8bfb\u53d6\u672a\u63d0\u4ea4\u7684\u6570\u636e\uff0c\u4e8b\u52a1\u4e0d\u4f1a\u5f3a\u5236\u56de\u6eda\u3002<\/li>\n\n\n\n<li><strong>READ COMMITTED<\/strong>\uff1a\u8fd9\u662f\u9ed8\u8ba4\u7684\u9694\u79bb\u7ea7\u522b\uff0c\u4e8b\u52a1\u63d0\u4ea4\u524d\u9700\u8981\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\uff0c\u4e0d\u4f1a\u53d1\u751f\u8bfb\u53d6\u810f\u6570\u636e\uff0c\u82e5\u51fa\u73b0\u6b7b\u9501\u6216\u8d44\u6e90\u4e89\u7528\uff0c\u4e8b\u52a1\u53ef\u80fd\u4f1a\u56de\u6eda\u3002<\/li>\n\n\n\n<li><strong>REPEATABLE READ<\/strong> \u548c <strong>SERIALIZABLE<\/strong>\uff1a\u8f83\u9ad8\u7684\u9694\u79bb\u7ea7\u522b\u4f1a\u66f4\u4e25\u683c\u5730\u63a7\u5236\u6570\u636e\u4e00\u81f4\u6027\uff0c\u907f\u514d\u4e0d\u53ef\u91cd\u590d\u8bfb\u548c\u5e7b\u8bfb\uff0c\u4f46\u4e5f\u53ef\u80fd\u56e0\u4e3a\u9501\u7b49\u5f85\u3001\u6b7b\u9501\u7b49\u95ee\u9898\u89e6\u53d1\u4e8b\u52a1\u56de\u6eda\u3002<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">17. <strong>\u81ea\u52a8\u56de\u6eda\u4e0e SQL Server \u7684\u900f\u660e\u6570\u636e\u52a0\u5bc6\uff08TDE\uff09<\/strong><\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 SQL Server \u7684\u900f\u660e\u6570\u636e\u52a0\u5bc6\uff08TDE\uff09\u65f6\uff0c\u4efb\u4f55\u5bf9\u6570\u636e\u5e93\u52a0\u5bc6\u5bc6\u94a5\u7684\u635f\u574f\u6216\u8bbf\u95ee\u95ee\u9898\u4e5f\u53ef\u80fd\u5bfc\u81f4\u4e8b\u52a1\u56de\u6eda\u3002\u5982\u679c\u6570\u636e\u5e93\u7684\u52a0\u5bc6\u5bc6\u94a5\u6216\u8bc1\u4e66\u4e22\u5931\uff0cSQL Server \u5c06\u65e0\u6cd5\u6267\u884c\u6b63\u5e38\u7684\u4e8b\u52a1\u64cd\u4f5c\uff0c\u8fd9\u65f6\u5019\u4f1a\u56de\u6eda\u4e8b\u52a1\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">\u603b\u7ed3\uff1a<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">SQL Server \u4e2d\u7684\u4e8b\u52a1\u56de\u6eda\u673a\u5236\u6d89\u53ca\u591a\u65b9\u9762\u7684\u5904\u7406\uff0c\u81ea\u52a8\u56de\u6eda\u7684\u573a\u666f\u4e0d\u4ec5\u5305\u62ec\u7cfb\u7edf\u9519\u8bef\u3001\u6b7b\u9501\u548c\u8d85\u65f6\u7b49\u60c5\u51b5\uff0c\u8fd8\u5305\u62ec\u6570\u636e\u5e93\u6062\u590d\u6a21\u5f0f\u3001\u8d44\u6e90\u4e0d\u8db3\u548c\u4e8b\u52a1\u9694\u79bb\u7ea7\u522b\u7b49\u56e0\u7d20\u3002\u7406\u89e3\u8fd9\u4e9b\u673a\u5236\u6709\u52a9\u4e8e\u66f4\u597d\u5730\u8bbe\u8ba1\u5e94\u7528\u7a0b\u5e8f\uff0c\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027\uff0c\u5e76\u5408\u7406\u5904\u7406\u6570\u636e\u5e93\u4e2d\u7684\u4e8b\u52a1\u56de\u6eda\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>SQL Server \u4e2d\u7684\u4e8b\u52a1\u56de\u6eda\u673a\u5236\u6d89\u53ca\u591a\u65b9\u9762\u7684\u5904\u7406\uff0c\u81ea\u52a8\u56de\u6eda\u7684\u573a\u666f\u4e0d\u4ec5\u5305\u62ec\u7cfb\u7edf\u9519\u8bef\u3001\u6b7b\u9501\u548c\u8d85\u65f6\u7b49\u60c5\u51b5\uff0c\u8fd8\u5305 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-812","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/812","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=812"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/812\/revisions"}],"predecessor-version":[{"id":813,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/812\/revisions\/813"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=812"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=812"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=812"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}