{"id":138023,"date":"2024-10-31T13:01:20","date_gmt":"2024-10-31T05:01:20","guid":{"rendered":"https:\/\/server.hk\/cnblog\/138023\/"},"modified":"2024-10-31T13:01:21","modified_gmt":"2024-10-31T05:01:21","slug":"sql-server%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%e7%9a%84%e4%ba%8b%e5%8b%99%e7%b5%82%e6%ad%a2%e6%b5%81%e7%a8%8b","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/138023\/","title":{"rendered":"SQL Server\u6578\u64da\u5eab\u66f4\u6539\u6578\u64da\u5eab\u72c0\u614b\u7684\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b"},"content":{"rendered":"<h1 id=\"sql-server%e6%95%b8%e6%93%9a%e5%ba%ab%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%e7%9a%84%e4%ba%8b%e5%8b%99%e7%b5%82%e6%ad%a2%e6%b5%81%e7%a8%8b-yUpLEbWkuC\">SQL Server\u6578\u64da\u5eab\u66f4\u6539\u6578\u64da\u5eab\u72c0\u614b\u7684\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b<\/h1>\n<p>\u5728\u4f7f\u7528SQL Server\u9032\u884c\u6578\u64da\u5eab\u7ba1\u7406\u6642\uff0c\u4e86\u89e3\u5982\u4f55\u66f4\u6539\u6578\u64da\u5eab\u7684\u72c0\u614b\u4ee5\u53ca\u5982\u4f55\u8655\u7406\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u9019\u4e0d\u50c5\u6709\u52a9\u65bc\u7dad\u8b77\u6578\u64da\u7684\u5b8c\u6574\u6027\uff0c\u9084\u80fd\u78ba\u4fdd\u7cfb\u7d71\u7684\u7a69\u5b9a\u6027\u548c\u6027\u80fd\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eSQL Server\u4e2d\u6578\u64da\u5eab\u72c0\u614b\u7684\u8b8a\u66f4\u53ca\u5176\u76f8\u95dc\u7684\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b\u3002<\/p>\n<h2 id=\"%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%e7%9a%84%e9%a1%9e%e5%9e%8b-yUpLEbWkuC\">\u6578\u64da\u5eab\u72c0\u614b\u7684\u985e\u578b<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u72c0\u614b\u53ef\u4ee5\u662f\u591a\u7a2e\u4e0d\u540c\u7684\u985e\u578b\uff0c\u4e3b\u8981\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>ONLINE<\/strong>\uff1a\u6578\u64da\u5eab\u8655\u65bc\u6b63\u5e38\u904b\u884c\u72c0\u614b\uff0c\u6240\u6709\u7528\u6236\u5747\u53ef\u8a2a\u554f\u3002<\/li>\n<li><strong>OFFLINE<\/strong>\uff1a\u6578\u64da\u5eab\u5df2\u88ab\u8a2d\u7f6e\u70ba\u96e2\u7dda\u72c0\u614b\uff0c\u7121\u6cd5\u8a2a\u554f\u3002<\/li>\n<li><strong>RESTORING<\/strong>\uff1a\u6578\u64da\u5eab\u6b63\u5728\u6062\u5fa9\u904e\u7a0b\u4e2d\uff0c\u7121\u6cd5\u8a2a\u554f\u3002<\/li>\n<li><strong>SUSPECT<\/strong>\uff1a\u6578\u64da\u5eab\u88ab\u6a19\u8a18\u70ba\u53ef\u7591\uff0c\u53ef\u80fd\u5b58\u5728\u640d\u58de\u6216\u5176\u4ed6\u554f\u984c\u3002<\/li>\n<li><strong>EMERGENCY<\/strong>\uff1a\u6578\u64da\u5eab\u9032\u5165\u7dca\u6025\u6a21\u5f0f\uff0c\u50c5\u9650\u65bc\u7cfb\u7d71\u7ba1\u7406\u54e1\u8a2a\u554f\u3002<\/li>\n<\/ul>\n<h2 id=\"%e6%9b%b4%e6%94%b9%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%e7%9a%84%e5%9f%ba%e6%9c%ac%e5%91%bd%e4%bb%a4-yUpLEbWkuC\">\u66f4\u6539\u6578\u64da\u5eab\u72c0\u614b\u7684\u57fa\u672c\u547d\u4ee4<\/h2>\n<p>\u8981\u66f4\u6539\u6578\u64da\u5eab\u7684\u72c0\u614b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0bSQL\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER DATABASE [\u6578\u64da\u5eab\u540d\u7a31] SET ONLINE;<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u5c07\u540d\u70ba\u201cTestDB\u201d\u7684\u6578\u64da\u5eab\u8a2d\u7f6e\u70ba\u5728\u7dda\u72c0\u614b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>ALTER DATABASE [TestDB] SET ONLINE;<\/code><\/pre>\n<h2 id=\"%e4%ba%8b%e5%8b%99%e7%b5%82%e6%ad%a2%e6%b5%81%e7%a8%8b-yUpLEbWkuC\">\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b<\/h2>\n<p>\u5728\u67d0\u4e9b\u60c5\u6cc1\u4e0b\uff0c\u53ef\u80fd\u9700\u8981\u7d42\u6b62\u6b63\u5728\u9032\u884c\u7684\u4e8b\u52d9\u3002\u9019\u901a\u5e38\u662f\u56e0\u70ba\u4e8b\u52d9\u904b\u884c\u6642\u9593\u904e\u9577\u6216\u51fa\u73fe\u6b7b\u9396\u3002SQL Server\u63d0\u4f9b\u4e86\u5e7e\u7a2e\u65b9\u6cd5\u4f86\u7d42\u6b62\u4e8b\u52d9\uff1a<\/p>\n<h3 id=\"%e4%bd%bf%e7%94%a8rollback%e5%91%bd%e4%bb%a4-yUpLEbWkuC\">\u4f7f\u7528ROLLBACK\u547d\u4ee4<\/h3>\n<p>\u7576\u9700\u8981\u64a4\u92b7\u4e00\u500b\u4e8b\u52d9\u6642\uff0c\u53ef\u4ee5\u4f7f\u7528ROLLBACK\u547d\u4ee4\u3002\u9019\u5c07\u64a4\u92b7\u81ea\u4e8b\u52d9\u958b\u59cb\u4ee5\u4f86\u6240\u505a\u7684\u6240\u6709\u66f4\u6539\u3002<\/p>\n<pre><code>ROLLBACK TRANSACTION;<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8kill%e5%91%bd%e4%bb%a4-yUpLEbWkuC\">\u4f7f\u7528KILL\u547d\u4ee4<\/h3>\n<p>\u5982\u679c\u9700\u8981\u7d42\u6b62\u7279\u5b9a\u7684\u6703\u8a71\uff0c\u53ef\u4ee5\u4f7f\u7528KILL\u547d\u4ee4\u3002\u9019\u6703\u7d42\u6b62\u6307\u5b9a\u7684\u6703\u8a71ID\uff08SPID\uff09\uff0c\u4e26\u4e14\u6703\u81ea\u52d5\u56de\u6efe\u8a72\u6703\u8a71\u4e2d\u7684\u6240\u6709\u672a\u63d0\u4ea4\u7684\u4e8b\u52d9\u3002<\/p>\n<pre><code>KILL [SPID];<\/code><\/pre>\n<p>\u4f8b\u5982\uff0c\u82e5\u8981\u7d42\u6b62SPID\u70ba53\u7684\u6703\u8a71\uff0c\u53ef\u4ee5\u4f7f\u7528\uff1a<\/p>\n<pre><code>KILL 53;<\/code><\/pre>\n<h2 id=\"%e4%ba%8b%e5%8b%99%e7%b5%82%e6%ad%a2%e5%be%8c%e7%9a%84%e6%95%b8%e6%93%9a%e5%ba%ab%e7%8b%80%e6%85%8b%e6%aa%a2%e6%9f%a5-yUpLEbWkuC\">\u4e8b\u52d9\u7d42\u6b62\u5f8c\u7684\u6578\u64da\u5eab\u72c0\u614b\u6aa2\u67e5<\/h2>\n<p>\u5728\u7d42\u6b62\u4e8b\u52d9\u5f8c\uff0c\u6aa2\u67e5\u6578\u64da\u5eab\u7684\u72c0\u614b\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8a62\u4f86\u6aa2\u67e5\u6578\u64da\u5eab\u7684\u7576\u524d\u72c0\u614b\uff1a<\/p>\n<pre><code>SELECT name, state_desc FROM sys.databases;<\/code><\/pre>\n<p>\u9019\u5c07\u8fd4\u56de\u6240\u6709\u6578\u64da\u5eab\u7684\u540d\u7a31\u53ca\u5176\u7576\u524d\u72c0\u614b\uff0c\u5e6b\u52a9\u7ba1\u7406\u54e1\u4e86\u89e3\u7cfb\u7d71\u7684\u5065\u5eb7\u72c0\u6cc1\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-yUpLEbWkuC\">\u7d50\u8ad6<\/h2>\n<p>\u5728SQL Server\u4e2d\uff0c\u6578\u64da\u5eab\u72c0\u614b\u7684\u7ba1\u7406\u548c\u4e8b\u52d9\u7684\u7d42\u6b62\u6d41\u7a0b\u662f\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u548c\u7cfb\u7d71\u7a69\u5b9a\u6027\u7684\u95dc\u9375\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528ALTER DATABASE\u3001ROLLBACK\u548cKILL\u547d\u4ee4\uff0c\u6578\u64da\u5eab\u7ba1\u7406\u54e1\u53ef\u4ee5\u6709\u6548\u5730\u63a7\u5236\u6578\u64da\u5eab\u7684\u904b\u884c\u72c0\u614b\uff0c\u4e26\u5728\u5fc5\u8981\u6642\u7d42\u6b62\u4e0d\u7576\u7684\u4e8b\u52d9\u3002\u4e86\u89e3\u9019\u4e9b\u57fa\u672c\u64cd\u4f5c\u5c07\u6709\u52a9\u65bc\u63d0\u9ad8\u6578\u64da\u5eab\u7ba1\u7406\u7684\u6548\u7387\u548c\u5b89\u5168\u6027\u3002<\/p>\n<p>\u5982\u9700\u9032\u4e00\u6b65\u4e86\u89e3\u6709\u95dc\u6578\u64da\u5eab\u7ba1\u7406\u7684\u8cc7\u8a0a\uff0c\u60a8\u53ef\u4ee5\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\uff0c\u63a2\u7d22\u66f4\u591a\u6709\u95dc<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u548c<a href=\"https:\/\/server.hk\">\u96f2\u4f3a\u670d\u5668<\/a>\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3SQL Server\u6578\u64da\u5eab\u4e2d\u66f4\u6539\u6578\u64da\u5eab\u72c0\u614b\u7684\u4e8b\u52d9\u7d42\u6b62\u6d41\u7a0b\uff0c\u78ba\u4fdd\u6578\u64da\u5b8c\u6574\u6027\u8207\u7cfb\u7d71\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-138023","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138023","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=138023"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138023\/revisions"}],"predecessor-version":[{"id":138024,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/138023\/revisions\/138024"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=138023"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=138023"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=138023"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}