?? 6333.htm
字號:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>MS SQL基礎教程:移動數(shù)據(jù)庫 - 編程入門網(wǎng)</title>
<meta name="keywords" content="MS SQL基礎教程:移動數(shù)據(jù)庫">
<meta name="description" content="MS SQL基礎教程:移動數(shù)據(jù)庫">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="/images/style.css" rel="stylesheet" type="text/css" />
<script src="/js1/head.js"></script>
</head>
<body leftmargin="0" topmargin="0" bgcolor="#efefef" oncopy=nocopy()>
<TABLE width="760" cellPadding="0" cellSpacing="0" bgcolor="#eff7fe" align="center">
<TR>
<TD><a href="/index.htm"><img src="/images/logo1.gif" width="150" height="60" border="0"></a></TD>
<TD width="470" align="right"><script src="/js1/top.js"></script></TD>
<TD width="125" align="center"><script src="/js1/topsy.js"></script></TD>
</TR>
</TABLE>
<table width="760" border="0" cellpadding="1" cellspacing="0" class="bklan" align="center">
<tr>
<td align="center" bgcolor="#eff7fe" height="24"> | <a href='/Programming/index.htm'>編程語言</a> | <a href='/webkf/index.htm'>web開發(fā)</a> | <a href='/data/index.htm'>數(shù)據(jù)庫</a> | <a href='/Network/index.htm'>網(wǎng)絡技術</a> | <a href='/OS/index.htm'>操作系統(tǒng)</a> | <a href='/Servers/index.htm'>服務器</a> | <a href='/web/index.htm'>網(wǎng)頁設計</a> | <a href='/Design/index.htm'>圖形設計</a> | <a href='/Office/index.htm'>辦公軟件</a> | <a href='/soft/index.htm'>常用軟件</a> | <a href='/shadu/index.htm'>殺毒頻道</a> | <a href='/PC/index.htm'>學電腦</a> |</td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="760" align="center" bgcolor="#ffffff" border="0">
<tr>
<td align="center"><script src="/js1/content1.js"></script></td>
</tr>
</table>
<table width="760" border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="25" background="/templets/img/31bg3.gif" align="left" class="guidet"> → 當前位置:<a href='http://www.bianceng.cn/'>首頁</a>→<a href='/data/index.htm'>數(shù)據(jù)庫</a>→<a href='/data/SQLServer/index.htm'>SQL Server</a>→<a href='/data/SQLServer/jc/index.htm'>SQL Server教程</a>→正文</td>
</tr>
</table>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td valign="top" class="guidet" width="595"><table width="100%" border="0" cellpadding="0" cellspacing="0" class="ct">
<tr>
<td align="center" valign="middle" class="til"><h3> MS SQL基礎教程:移動數(shù)據(jù)庫 </h3>
發(fā)布時間:2007-12-25 來源:網(wǎng)絡/責編:編程入門 作者:佚名<br />
<script src="/js1/468.js"></script>
</td>
</tr>
<tr>
<td style="font-size:14px" align="left" class="til"><table border="0" align="right" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><script src="/js1/300.js"></script></td>
</tr>
</table><p> 在SQL Server 中可以使用拆分(Detach)和附加(Attach)的方法來移動數(shù)據(jù)庫。拆分數(shù)據(jù)庫是從服務器中移去邏輯數(shù)據(jù)庫,但不會將操作系統(tǒng)中的數(shù)據(jù)庫文件刪除。附加數(shù)據(jù)庫將會創(chuàng)建一個新的數(shù)據(jù)庫,并復制存儲在已有的數(shù)據(jù)庫文件和事務日志文件中的數(shù)據(jù)。使用系統(tǒng)存儲過程Sp_detach_db 來拆分數(shù)據(jù)庫,用系統(tǒng)存儲過程Sp_attach_db 來附加數(shù)據(jù)庫。</p>
<p> Sp_detach_db 系統(tǒng)存儲過程的語法如下:</p>
<p> sp_detach_db [@dbname =] 'database_name'</p>
<p> [, [@skipchecks =] 'skipchecks']</p>
<p> 其中[@skipchecks =] 'skipchecks'子句中Skipchecks 的值為True 或False。 當Skipchecks的值為True 時,指定在執(zhí)行此過程之前不需要對數(shù)據(jù)庫中的所有表執(zhí)行UPDATE STATISTICS命令;為False 時,則需要執(zhí)行UPDATE STATISTICS 命令。</p>
<p> Sp_attach_db 系統(tǒng)存儲過程的語法如下:</p>
<p> sp_attach_db [@dbname =] 'dbname',</p>
<p> [@filename1 =] 'filename_n' [,...16]</p>
<p> 其中“filename_n”包括文件的路徑和物理名稱。最多可指定16 個文件。文件中必須包含主數(shù)據(jù)庫文件。如果需要附加的文件超過了16 個,就必須使用帶FOR ATTACH 子句的CREATE DATABASE 命令來代替。</p>
<p> <strong>注意</strong>:Sp_attach_db系統(tǒng)存儲過程中只能作用于那些已經(jīng)用Sp_detach_db系統(tǒng)存儲過程從服務器中拆分出來的數(shù)據(jù)庫。</p>
<p> 例6-16:移動數(shù)據(jù)庫mytest 到E:SQL Data 目錄下。---www.bianceng.cn</p>
<p> (1) 在SQL Server Query Analyzer 中運行系統(tǒng)存儲過程Sp_helpdb, 得到mytest數(shù)據(jù)庫所包含的文件名稱、數(shù)量、類型、存放位置等信息。命令語句如下:</p>
<p> exec sp_helpdb mytest</p>
<p> <img onclick="get_larger(this)" alt="" src="/upimg/071226/11b61164K1014460.gif" /></p>
<p> (2) 在SQL Server Query Analyzer 中運行Sp_detach_db 系統(tǒng)存儲過程,拆分mytest數(shù)據(jù)庫。命令語句如下:</p>
<p> exec sp_detach_db mytest, true </p>
<p> 運行結果如下:</p>
<p> Successfully detached database 'mytest1'.</p>
<p> DBCC execution completed. If DBCC printed error messages, contact your system administrator.</p>
<p> (3) 在操作系統(tǒng)的文件夾窗口中用剪切或粘貼的方式直接將與數(shù)據(jù)庫相關的操作系統(tǒng)文件移動到E: SQL Data 2000 Server 目錄下。即將D:SQL Datamytest_Data.MDF 文件和D:SQLDatamytest_Log.LDF 文件移到E: SQL Data 2000</p>
<p> (4) 在SQL Server Query Analyzer 中運行Sp_attach_db 系統(tǒng)存儲過程,附加文件到mytest 數(shù)據(jù)庫。命令語句如下:</p>
<p> exec sp_attach_db @dbname = 'mytest',</p>
<p> @filename1 = 'e:sql datamytest_data.mdf',</p>
<p> @filename2 = 'e:sql datamytest_log.ldf'</p>
<p> 運行結果如下:</p>
<p> Successfully attached database 'mytest'.</p>
<p> 至此已完成了數(shù)據(jù)庫的移動工作,可在Enterprise Manager 中查看mytest 數(shù)據(jù)庫的信息,也可以在SQL Server Query Analyzer 中運行系統(tǒng)存儲過程Sp_helpdb 來查看移動是否成功。</p>
<p> <a href="/data/SQLServer/jc/200712/6352.htm">查看全套"MS SQL入門基礎教程"</a></p><center><br /><script src="/js1/4682.js"></script></center>
<p>上一篇:<a href='/data/SQLServer/jc/200712/6332.htm'>MS SQL基礎教程:壓縮數(shù)據(jù)庫</a> 下一篇:<a href='/data/SQLServer/jc/200712/6334.htm'>MS SQL基礎教程:數(shù)據(jù)庫維護計劃</a> </p></td>
</tr>
<tr>
<td align="left" style="font-size:14px;" height="25"><IMG src="/images/t0.gif" width="12" height="12" align=absMiddle><strong>相關文章</strong><br /><table width='100%' border='0' cellspacing='0' cellpadding='0'>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6332.htm">MS SQL基礎教程:壓縮數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6334.htm">MS SQL基礎教程:數(shù)據(jù)庫維護計劃</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6331.htm">MS SQL基礎教程:刪除數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6335.htm">MS SQL基礎教程:系統(tǒng)數(shù)據(jù)庫</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6330.htm">MS SQL基礎教程:更改數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6336.htm">MS SQL基礎教程:實例數(shù)據(jù)庫</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6329.htm">MS SQL基礎教程:瀏覽數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6337.htm">MS SQL基礎教程:創(chuàng)建數(shù)據(jù)庫表</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6328.htm">MS SQL基礎教程:數(shù)據(jù)庫屬性設置</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6338.htm">MS SQL基礎教程:創(chuàng)建和使用約束</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6327.htm">MS SQL基礎教程:創(chuàng)建數(shù)據(jù)庫</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6339.htm">MS SQL基礎教程:自定義數(shù)據(jù)類型</a><br/>
</td>
</tr>
<tr>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6326.htm">MS SQL基礎教程:企業(yè)管理器的常見用途</a><br/>
</td>
<td width='50%'>
·<a href="/data/SQLServer/jc/200712/6340.htm">MS SQL基礎教程:SQL數(shù)據(jù)庫表的修改</a><br/>
</td>
</tr>
</table>
</td>
</tr>
</table>
</td>
<td width="165" valign="top" class="guideb"><script src="/js1/1601.js"></script><table width="100%" border="0" cellpadding="0" cellspacing="0" valign="top">
<tr>
<td height="25" align="center" background="/templets/img/31bg3.gif"><strong>閱讀排行</strong></td>
</tr>
<tr>
<td>·<a href="/data/SQLServer/jc/200712/6352.htm">MS SQL Server入門教程</a><br/>
·<a href="/data/SQLServer/jc/200807/10974.htm">MS SQL基礎教程:存儲過程</a><br/>
·<a href="/data/SQLServer/jc/200705/1189.htm">sql語言教程</a><br/>
·<a href="/data/SQLServer/jc/200807/10973.htm">MS SQL基礎教程:創(chuàng)建存儲</a><br/>
·<a href="/data/SQLServer/jc/200705/1182.htm">sql字符串函數(shù)</a><br/>
·<a href="/data/SQLServer/jc/200712/6301.htm">MS SQL基礎教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6302.htm">MS SQL基礎教程:SQL Serve</a><br/>
·<a href="/data/SQLServer/jc/200712/6314.htm">MS SQL基礎教程:數(shù)據(jù)類型</a><br/>
·<a href="/data/SQLServer/jc/200705/1188.htm">Sql語言基礎</a><br/>
·<a href="/data/SQLServer/jc/200712/6311.htm">MS SQL基礎教程:Transact-</a><br/>
·<a href="/data/SQLServer/jc/200712/6312.htm">MS SQL基礎教程:SQL變量</a><br/>
·<a href="/data/SQLServer/jc/200705/1184.htm">sql基本語句</a><br/>
·<a href="/data/SQLServer/jc/200807/10972.htm">MS SQL基礎教程:管理存儲</a><br/>
·<a href="/data/SQLServer/jc/200712/6306.htm">MS SQL基礎教程:數(shù)據(jù)庫基</a><br/>
·<a href="/data/SQLServer/jc/200705/1178.htm">sql數(shù)據(jù)表</a><br/>
</td>
</tr>
<tr>
<td><script src="/js1/1602.js"></script></td>
</tr>
<tr>
<td height="25" align="center" background="/templets/img/31bg3.gif"><strong>最新文章</strong></td>
</tr>
<tr>
<td><script src="/plus/js/0.js" language="javascript"></script></td>
</tr>
</table></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" width="760" align="center" bgcolor="#ffffff" border="0">
<tr>
<td align="center"><script src="/js1/content2.js"></script></td>
</tr>
</table>
<table width="760" border="0" cellspacing="0" cellpadding="0" align="center">
<tr height="26">
<td bgcolor="#e1f0fd" width="48"></td>
<td bgcolor="#6ab3f4" width="35"></td>
<td bgcolor="#0a518f" colspan="2" width="4"></td>
<td bgcolor="#c0c0c0" width="530" align="center"><a title="將本站設為你的首頁" onclick="this.style.behavior='url(#default#homepage)';this.sethomepage('http://www.bianceng.cn');return false;" href="http://www.bianceng.cn/">設為首頁</a> | <a class="navmenu"
title="將本站加入到你的收藏夾"
href="javascript:window.external.AddFavorite(location.href,document.title)">加入收藏</a> | <a href="/about/about.htm">關于本站</a> | <a href="/plus/flink.php">友情鏈接</a> | <a href="/about/banquan.htm">版權聲明</a> | <a href="/plus/sitemap.html">網(wǎng)站地圖</a> | <a href="/plus/rssmap.html">RSS訂閱</a></td>
<td bgcolor="#0a518f" colspan="2" width="4"></td>
<td bgcolor="#6ab3f4" width="32"></td>
<td bgcolor="#e1f0fd" width="47"></td>
</tr>
<tr height="26">
<td colspan="9" bgcolor="#FFFFFF" align="center">編程入門網(wǎng) 版權所有,bianceng.cn,All Rights Reserved. <script src="/js/tongji.js"></script> 閱讀次數(shù):<script src="/plus/count.php?aid=6333&mid=0" language="javascript"></script></td>
</tr>
</table>
</body>
</html>
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -