{"id":158,"date":"2011-09-06T17:49:49","date_gmt":"2011-09-06T09:49:49","guid":{"rendered":"http:\/\/www.kiccleaf.com\/?p=158"},"modified":"2011-09-27T09:22:16","modified_gmt":"2011-09-27T01:22:16","slug":"mssql2005-mssql2008%e6%95%b0%e6%8d%ae%e5%ba%93%e6%89%b9%e9%87%8f%e5%a4%87%e4%bb%bd%e5%92%8c%e8%bf%98%e5%8e%9f%e8%84%9a%e6%9c%ac","status":"publish","type":"post","link":"http:\/\/www.kiccleaf.com\/?p=158","title":{"rendered":"MSSQL2005-MSSQL2008\u6570\u636e\u5e93\u6279\u91cf\u5907\u4efd\u548c\u8fd8\u539f\u811a\u672c"},"content":{"rendered":"<p>\u7531\u4e8e\u9879\u76ee\u5173\u7cfb\uff0c\u4e00\u53f0\u670d\u52a1\u5668\u6570\u636e\u5e93\u505a\u8fc1\u79fb\u5de5\u4f5c\uff0c\u5c06\u8fd1\u4e24\u767e\u591a\u4e2a\u6570\u636e\u5e93\u4e00\u4e2a\u4e2a\u5907\u4efd\u8981\u6d6a\u8d39\u5f88\u591a\u65f6\u95f4\uff0c\u5728\u6b64\u91c7\u7528\u4e86\u751f\u6210\u811a\u672c\u7684\u65b9\u5f0f\u4e0e\u5927\u5bb6\u5206\u4eab\uff0c\u5e0c\u671b\u7ed9\u9700\u8981\u7684\u4eba\u6709\u5e2e\u52a9\u3002\u5df2\u7ecf\u6d4b\u8bd5\u9002\u5408MSSQL2005-MSSQL2008\u6570\u636e\u5e93\u5907\u4efd\u548c\u8fd8\u539f\u811a\u672c\uff0c\u672a\u6d4b\u8bd5MSSQL2000\u6570\u636e\u5e93\u3002<br \/>\n2011-09-27 \u6dfb\u52a0\u5206\u79bb\u6570\u636e\u5e93\u548c\u9644\u52a0\u6570\u636e\u811a\u672c<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n--\u6279\u91cf\u751f\u6210\u5206\u79bb\u811a\u672c\r\nuse master\r\nselect 'EXEC sp_detach_db '''+name+''', ''true'';'  from sysdatabases \r\n\r\n--\u5355\u4e2a\u6570\u636e\u5e93\u5206\u79bb\r\nEXEC sp_detach_db '&lt;database name&gt;', 'true';\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n--\u6279\u91cf\u751f\u6210\u6570\u636e\u5e93\u9644\u52a0\u811a\u672c\r\nuse master\r\nselect 'CREATE DATABASE &#x5B;'+name+'] ON ( FILENAME = N''C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\Data\\'+name+'.mdf'' ),( FILENAME = N''C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\Data\\'+name+'_log.ldf'' ) FOR ATTACH ;' from sysdatabases \r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n--\u5355\u4e2a\u6570\u636e\u5e93\u9644\u52a0\u811a\u672c\r\nuse master\r\nCREATE DATABASE &#x5B;database_name] ON \r\n( FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\Data\\&lt;database name&gt;.mdf' ),\r\n( FILENAME = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL10.MSSQLSERVER\\MSSQL\\Data\\&lt;database name&gt;.ldf' )\r\n FOR ATTACH ;\r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nuse master\r\n--\u751f\u6210\u6279\u91cf\u5220\u9664\u6570\u636e\u5e93\u811a\u672c\r\nselect 'DROP DATABASE  &#x5B;'+name+'];' from sysdatabases \r\n<\/pre>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\nuse master\r\n--\u751f\u6210\u5907\u4efd\u811a\u672c\uff0c\u53ef\u5728\u5217\u8868\u4e2d\u590d\u5236\u751f\u6210\u7684TSQL\u4ee3\u7801\r\nselect 'BACKUP DATABASE &#x5B;'+name+'] TO DISK = ''f:\\autobak\\'+name+'.bak'' WITH NOINIT , NOUNLOAD , NOSKIP , STATS = 10, NOFORMAT ;' from sysdatabases \r\n<\/pre>\n<p>\u5982\u56fe\u6240\u793a\uff1a<br \/>\n<a href=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/1.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/1.jpg\" alt=\"\" title=\"1\" width=\"727\" height=\"120\" class=\"alignnone size-full wp-image-159\" srcset=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/1.jpg 727w, http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/1-300x49.jpg 300w\" sizes=\"auto, (max-width: 727px) 100vw, 727px\" \/><\/a><br \/>\n\u590d\u5236\u4ee5\u4e0a\u5217\u8868TSQL\u811a\u672c\u5728\u8fc1\u79fb\u7684\u670d\u52a1\u5668\u4e0a\u8fdb\u884c\u6267\u884c\u5907\u4efd\u6570\u636e\u5e93<\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n--\u751f\u6210\u8fd8\u539f\u811a\u672c\uff0c\u6570\u636e\u5e93\u5b58\u653e\u76ee\u5f55\u4e0e\u8fc1\u79fb\u673a\u5668\u540c\u6837\u65f6\u7528\u6b64\u811a\u672c\r\nselect 'BACKUP DATABASE &#x5B;'+name+'] FROM DISK=''f:\\autobak\\'+name+'.bak'' WITH REPLACE ;' from sysdatabases\r\n\r\nselect 'alter database &#x5B;'+name+']  set online ;' from sysdatabases \r\n<\/pre>\n<p>\u5982\u56fe\u6240\u793a\uff1a<br \/>\n<a href=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/2.jpg\"><img loading=\"lazy\" decoding=\"async\" src=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/2.jpg\" alt=\"\" title=\"2\" width=\"382\" height=\"225\" class=\"alignnone size-full wp-image-160\" srcset=\"http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/2.jpg 382w, http:\/\/www.kiccleaf.com\/wp-content\/uploads\/2011\/09\/2-300x176.jpg 300w\" sizes=\"auto, (max-width: 382px) 100vw, 382px\" \/><\/a><\/p>\n<pre class=\"brush: sql; title: ; notranslate\" title=\"\">\r\n--\u6570\u636e\u5e93\u8fc1\u79fb\u5230\u5176\u4ed6\u673a\u5668\uff0c\u76d8\u7b26\u548c\u76ee\u5f55\u53d1\u751f\u53d8\u5316\u65f6\uff0c\u5c31\u9700\u8981\u505a\u8fd8\u539f\u914d\u7f6e\u76f8\u5e94\u7684\u8def\u5f84\r\n--D:\\Data \u76ee\u5f55\u4e3a\u6570\u636e\u5e93\u5b58\u653e\u76ee\u5f55\u548c\u65e5\u5fd7\u5b58\u653e\u76ee\u5f55\uff0c\u4e5f\u53ef\u5c06\u4e24\u4e2a\u76ee\u5f55\u5206\u5176\u4ed6\u76d8\u7b26\u53ef\u63d0\u5347IO\u7684\u64cd\u4f5c\u6548\u7387\r\n--\u6ce8\u610f\uff1aMOVE \u540e\u9762\u7684\u6570\u636e\u903b\u8f91\u540d\u79f0\uff0c\u5982\u679c\u662f\u72ec\u7acb\u521b\u5efa\u7684\u6570\u636e\u903b\u8f91\u540d\u4e0d\u4f1a\u9519\u3002\r\n--     \u5047\u5982\u662f\u4eceA\u6570\u636e\u5e93\u8fd8\u539f\u6210B\u540d\u79f0\u6570\u636e\u65f6\uff0c\u4ed6\u7684\u903b\u8f91\u540d\u79f0\u8fd8\u662fA\uff0c\u6240\u4ee5\u6b64\u5904\u5927\u5bb6\u4e00\u5b9a\u8981\u6ce8\u610f\r\nselect 'RESTORE DATABASE &#x5B;'+name+'] FROM DISK=''d:\\autobak\\'+name+'.bak'' \r\nWITH MOVE ''' +name+ ''' TO ''d:\\Data\\'+name+'.mdf'',\r\nMOVE '''+name+'_log'' TO ''d:\\Data\\'+name+'_log.ldf'';' from sysdatabases\r\n<\/pre>\n<p>\u751f\u6210\u4ee5\u4e0a\u811a\u672c\uff0c\u53ef\u628a\u6570\u636e\u5e93\u590d\u5236\u5230\u90e8\u7f72\u673a\u5668\u4e0a\u540e\uff0c\u4fee\u6539\u597dbak\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u6267\u884cTSQL\u811a\u672c\u5373\u53ef<br \/>\n\u6709\u4ec0\u4e48\u95ee\u9898\u6b22\u8fce\u5927\u5bb6\u5171\u540c\u63a2\u8ba8\uff0c\u6709\u4e0d\u8db3\u4e4b\u5904\u6216\u662f\u6709\u66f4\u597d\u7684\u65b9\u6cd5\u5e0c\u671b\u5927\u5bb6\u80fd\u4e0e\u6211\u5206\u4eab\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u7531\u4e8e\u9879\u76ee\u5173\u7cfb\uff0c\u4e00\u53f0\u670d\u52a1\u5668\u6570\u636e\u5e93\u505a\u8fc1\u79fb\u5de5\u4f5c\uff0c\u5c06\u8fd1\u4e24\u767e&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"http:\/\/www.kiccleaf.com\/?p=158\">Continue reading<span class=\"screen-reader-text\">MSSQL2005-MSSQL2008\u6570\u636e\u5e93\u6279\u91cf\u5907\u4efd\u548c\u8fd8\u539f\u811a\u672c<\/span><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":1,"footnotes":""},"categories":[1],"tags":[30,32,31],"class_list":["post-158","post","type-post","status-publish","format-standard","hentry","category-windows","tag-sql2008sql2005","tag-tsql","tag-31","entry"],"views":4317,"_links":{"self":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/158","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=158"}],"version-history":[{"count":0,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=\/wp\/v2\/posts\/158\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=158"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=158"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.kiccleaf.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=158"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}