{"id":170507,"date":"2024-11-06T22:32:19","date_gmt":"2024-11-06T14:32:19","guid":{"rendered":"https:\/\/server.hk\/cnblog\/170507\/"},"modified":"2024-11-06T22:32:20","modified_gmt":"2024-11-06T14:32:20","slug":"%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9mssql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9a%e4%b8%80%e7%a8%ae%e6%9b%b4%e7%b0%a1%e6%98%93%e7%9a%84%e6%96%b9%e5%bc%8f%ef%bc%88%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9mssql","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/170507\/","title":{"rendered":"\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\uff1a\u4e00\u7a2e\u66f4\u7c21\u6613\u7684\u65b9\u5f0f\uff08\u6279\u91cf\u6062\u5fa9mssql\u6578\u64da\u5eab\uff09"},"content":{"rendered":"<h1 id=\"%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9mssql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9a%e4%b8%80%e7%a8%ae%e6%9b%b4%e7%b0%a1%e6%98%93%e7%9a%84%e6%96%b9%e5%bc%8f-SheRubfIyN\">\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\uff1a\u4e00\u7a2e\u66f4\u7c21\u6613\u7684\u65b9\u5f0f<\/h1>\n<p>\u5728\u6578\u64da\u7ba1\u7406\u7684\u904e\u7a0b\u4e2d\uff0c\u6578\u64da\u5eab\u7684\u6062\u5fa9\u662f\u4e00\u9805\u81f3\u95dc\u91cd\u8981\u7684\u4efb\u52d9\u3002\u7279\u5225\u662f\u5c0d\u65bc\u4f7f\u7528Microsoft SQL Server\uff08MSSQL\uff09\u7684\u4f01\u696d\u4f86\u8aaa\uff0c\u6279\u91cf\u6062\u5fa9\u6578\u64da\u5eab\u7684\u9700\u6c42\u65e5\u76ca\u589e\u52a0\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\u7684\u7c21\u6613\u65b9\u6cd5\uff0c\u5e6b\u52a9\u7528\u6236\u66f4\u9ad8\u6548\u5730\u7ba1\u7406\u6578\u64da\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc%e9%9c%80%e8%a6%81%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9mssql%e6%95%b8%e6%93%9a%e5%ba%ab%ef%bc%9f-SheRubfIyN\">\u70ba\u4ec0\u9ebc\u9700\u8981\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\uff1f<\/h2>\n<p>\u6578\u64da\u5eab\u7684\u6062\u5fa9\u901a\u5e38\u662f\u56e0\u70ba\u6578\u64da\u640d\u58de\u3001\u610f\u5916\u522a\u9664\u6216\u7cfb\u7d71\u6545\u969c\u7b49\u539f\u56e0\u3002\u5c0d\u65bc\u5927\u578b\u4f01\u696d\u4f86\u8aaa\uff0c\u6578\u64da\u5eab\u7684\u6578\u91cf\u53ef\u80fd\u975e\u5e38\u9f90\u5927\uff0c\u624b\u52d5\u6062\u5fa9\u6bcf\u500b\u6578\u64da\u5eab\u4e0d\u50c5\u8017\u6642\uff0c\u9084\u5bb9\u6613\u51fa\u932f\u3002\u56e0\u6b64\uff0c\u6279\u91cf\u6062\u5fa9\u6210\u70ba\u4e86\u4e00\u7a2e\u66f4\u70ba\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9%e7%9a%84%e5%9f%ba%e6%9c%ac%e6%a6%82%e5%bf%b5-SheRubfIyN\">\u6279\u91cf\u6062\u5fa9\u7684\u57fa\u672c\u6982\u5ff5<\/h2>\n<p>\u6279\u91cf\u6062\u5fa9\u662f\u6307\u540c\u6642\u6062\u5fa9\u591a\u500b\u6578\u64da\u5eab\u7684\u904e\u7a0b\u3002\u9019\u4e00\u904e\u7a0b\u53ef\u4ee5\u901a\u904e\u8173\u672c\u81ea\u52d5\u5316\uff0c\u5f9e\u800c\u6e1b\u5c11\u4eba\u5de5\u64cd\u4f5c\u7684\u9700\u6c42\u3002\u4f7f\u7528T-SQL\uff08Transact-SQL\uff09\u8a9e\u8a00\uff0c\u53ef\u4ee5\u7de8\u5beb\u8173\u672c\u4f86\u5be6\u73fe\u6279\u91cf\u6062\u5fa9\u7684\u529f\u80fd\u3002<\/p>\n<h3 id=\"%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9%e7%9a%84%e6%ad%a5%e9%a9%9f-SheRubfIyN\">\u6279\u91cf\u6062\u5fa9\u7684\u6b65\u9a5f<\/h3>\n<ul>\n<li><strong>\u6e96\u5099\u6578\u64da\u5eab\u5099\u4efd\u6587\u4ef6\uff1a<\/strong>\u78ba\u4fdd\u6240\u6709\u9700\u8981\u6062\u5fa9\u7684\u6578\u64da\u5eab\u90fd\u6709\u76f8\u61c9\u7684\u5099\u4efd\u6587\u4ef6\u3002<\/li>\n<li><strong>\u7de8\u5beb\u6062\u5fa9\u8173\u672c\uff1a<\/strong>\u4f7f\u7528T-SQL\u7de8\u5beb\u6279\u91cf\u6062\u5fa9\u7684\u8173\u672c\u3002<\/li>\n<li><strong>\u57f7\u884c\u8173\u672c\uff1a<\/strong>\u5728SQL Server Management Studio\uff08SSMS\uff09\u4e2d\u57f7\u884c\u8173\u672c\uff0c\u958b\u59cb\u6279\u91cf\u6062\u5fa9\u904e\u7a0b\u3002<\/li>\n<\/ul>\n<h3 id=\"%e7%a4%ba%e4%be%8b%ef%bc%9a%e6%89%b9%e9%87%8f%e6%81%a2%e5%be%a9%e8%85%b3%e6%9c%ac-SheRubfIyN\">\u793a\u4f8b\uff1a\u6279\u91cf\u6062\u5fa9\u8173\u672c<\/h3>\n<pre><code>\nDECLARE @DatabaseName NVARCHAR(255)\nDECLARE @BackupFile NVARCHAR(255)\nDECLARE @SQL NVARCHAR(MAX)\n\n-- \u5047\u8a2d\u6709\u4e00\u500b\u8868\u683c\u5b58\u5132\u6578\u64da\u5eab\u540d\u7a31\u548c\u5099\u4efd\u6587\u4ef6\u8def\u5f91\nDECLARE db_cursor CURSOR FOR \nSELECT DatabaseName, BackupFile FROM BackupList\n\nOPEN db_cursor\nFETCH NEXT FROM db_cursor INTO @DatabaseName, @BackupFile\n\nWHILE @@FETCH_STATUS = 0\nBEGIN\n    SET @SQL = 'RESTORE DATABASE ' + QUOTENAME(@DatabaseName) + \n                ' FROM DISK = ''' + @BackupFile + ''' WITH REPLACE'\n    EXEC sp_executesql @SQL\n    FETCH NEXT FROM db_cursor INTO @DatabaseName, @BackupFile\nEND\n\nCLOSE db_cursor\nDEALLOCATE db_cursor\n<\/code><\/pre>\n<p>\u4e0a\u8ff0\u8173\u672c\u9996\u5148\u5b9a\u7fa9\u4e86\u4e00\u500b\u6e38\u6a19\uff0c\u5f9e\u4e00\u500b\u540d\u70baBackupList\u7684\u8868\u4e2d\u9078\u53d6\u6578\u64da\u5eab\u540d\u7a31\u548c\u5099\u4efd\u6587\u4ef6\u8def\u5f91\u3002\u7136\u5f8c\uff0c\u901a\u904e\u5faa\u74b0\u904d\u6b77\u6bcf\u500b\u6578\u64da\u5eab\uff0c\u57f7\u884c\u6062\u5fa9\u64cd\u4f5c\u3002<\/p>\n<h2 id=\"%e6%b3%a8%e6%84%8f%e4%ba%8b%e9%a0%85-SheRubfIyN\">\u6ce8\u610f\u4e8b\u9805<\/h2>\n<p>\u5728\u9032\u884c\u6279\u91cf\u6062\u5fa9\u6642\uff0c\u6709\u5e7e\u500b\u6ce8\u610f\u4e8b\u9805\u9700\u8981\u8003\u616e\uff1a<\/p>\n<ul>\n<li><strong>\u78ba\u4fdd\u5099\u4efd\u6587\u4ef6\u7684\u5b8c\u6574\u6027\uff1a<\/strong>\u5728\u6062\u5fa9\u4e4b\u524d\uff0c\u6aa2\u67e5\u5099\u4efd\u6587\u4ef6\u662f\u5426\u5b8c\u6574\u4e14\u53ef\u7528\u3002<\/li>\n<li><strong>\u8003\u616e\u6062\u5fa9\u6642\u9593\uff1a<\/strong>\u6279\u91cf\u6062\u5fa9\u53ef\u80fd\u9700\u8981\u8f03\u9577\u7684\u6642\u9593\uff0c\u7279\u5225\u662f\u5c0d\u65bc\u5927\u578b\u6578\u64da\u5eab\u3002<\/li>\n<li><strong>\u76e3\u63a7\u6062\u5fa9\u904e\u7a0b\uff1a<\/strong>\u5728\u6062\u5fa9\u904e\u7a0b\u4e2d\uff0c\u61c9\u8a72\u76e3\u63a7\u9032\u5ea6\uff0c\u4ee5\u4fbf\u53ca\u6642\u8655\u7406\u53ef\u80fd\u51fa\u73fe\u7684\u554f\u984c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-SheRubfIyN\">\u7d50\u8ad6<\/h2>\n<p>\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\u662f\u4e00\u7a2e\u9ad8\u6548\u7684\u6578\u64da\u7ba1\u7406\u65b9\u6cd5\uff0c\u80fd\u5920\u986f\u8457\u6e1b\u5c11\u6062\u5fa9\u6642\u9593\u548c\u4eba\u529b\u6210\u672c\u3002\u901a\u904e\u4f7f\u7528T-SQL\u8173\u672c\uff0c\u81ea\u52d5\u5316\u6062\u5fa9\u904e\u7a0b\uff0c\u4f01\u696d\u53ef\u4ee5\u66f4\u597d\u5730\u61c9\u5c0d\u6578\u64da\u4e1f\u5931\u7684\u98a8\u96aa\uff0c\u78ba\u4fdd\u696d\u52d9\u7684\u9023\u7e8c\u6027\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u6709\u95dc\u6578\u64da\u5eab\u7ba1\u7406\u548c\u96f2\u670d\u52d9\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9 <a href=\"https:\/\/server.hk\">Server.HK<\/a>\uff0c\u6211\u5011\u63d0\u4f9b\u5404\u7a2e <a href=\"https:\/\/server.hk\">VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u5e6b\u52a9\u60a8\u66f4\u597d\u5730\u7ba1\u7406\u60a8\u7684\u6578\u64da\u548c\u61c9\u7528\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22\u6279\u91cf\u6062\u5fa9MSSQL\u6578\u64da\u5eab\u7684\u7c21\u6613\u65b9\u6cd5\uff0c\u63d0\u5347\u6578\u64da\u6062\u5fa9\u6548\u7387\uff0c\u7bc0\u7701\u6642\u9593\u8207\u8cc7\u6e90\uff0c\u78ba\u4fdd\u6578\u64da\u5b89\u5168\u7121\u6182\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-170507","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170507","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=170507"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170507\/revisions"}],"predecessor-version":[{"id":170508,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/170507\/revisions\/170508"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=170507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=170507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=170507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}