小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

SQL Server:用 SQL 語句還原數(shù)據(jù)庫(with move 選項用法)

 imzjw 2009-05-25

SQL Server:用 SQL 語句還原數(shù)據(jù)庫(with move 選項用法)

SQL Server:用 SQL 語句還原數(shù)據(jù)庫(with move 選項用法)


SQL Server:用 SQL 語句還原數(shù)據(jù)庫(with Move 選項用法)。

當我們把服務器A上的一個數(shù)據(jù)庫備份后,在服務器B上還原的時候,直接 restore 的時候,大多情況下都會出錯,可能的原因是數(shù)據(jù)庫的文件(數(shù)據(jù)和日志)在不同服務器上所在的 path 不同。這時候就需要 restore with move 選項,來把數(shù)據(jù)庫文件還原到目標 path 中。with move 的詳細語法:

MOVE 'logical_file_name' TO 'operating_system_file_name' [ ,...n ]
當我在把 SQL Server 2000 Instance(實例)中的數(shù)據(jù)庫 Nortwind,還原到 SQL Server 2005 Instance 中的時候,也需要使用 restore with move 選項來進行還原。

1. 查看 SQL Server 2000 中 Northwind 數(shù)據(jù)庫文件的邏輯文件名(logical file name)和物理文件路徑(operation system file name):
use Nothwind
go

select name, filename, * from dbo.sysfiles
name            filename
--------------  ------------------------------------------------------------------
Northwind      d:\program files\microsoft sql server\mssql$sqla\data\northwnd.mdf
Northwind_log  d:\program files\microsoft sql server\mssql$sqla\data\northwnd.ldf
2. 備份 SQL Server 2000.Northwind 數(shù)據(jù)庫
backup database Northwind to disk = 'c:\Northwind.bak'
3. 在 SQL Server 2005 Instance 中還原 Northwind 數(shù)據(jù)庫。
use master
go

restore database Northwind from disk = 'c:\Northwind.bak'
用普通方式 restore 的話,SQL Server 會報出一大堆的錯誤信息。

Msg 3634, Level 16, State 1, Line 1
The operating system returned the error '32(error not found)'
while attempting 'RestoreContainer::ValidateTargetForCreation'
on 'd:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.mdf'.

Msg 3156, Level 16, State 8, Line 1
File 'Northwind' cannot be restored to
'd:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.mdf'.
Use WITH MOVE to identify a valid location for the file.

Msg 3634, Level 16, State 1, Line 1
The operating system returned the error '32(error not found)'
while attempting 'RestoreContainer::ValidateTargetForCreation'
on 'd:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.ldf'.

Msg 3156, Level 16, State 8, Line 1
File 'Northwind_log' cannot be restored to
'd:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.ldf'.
Use WITH MOVE to identify a valid location for the file.

Msg 3119, Level 16, State 1, Line 1
Problems were identified while planning for the RESTORE statement. Previous messages provide details.

Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
4. 在 SQL Server 2005 中還原 Northwind 數(shù)據(jù)庫正確方法:restore with move。
SQL Server 2005 中數(shù)據(jù)文件所在目錄為:d:\microsoft sql server\mssql.1\mssql\data\

restore database Northwind from disk = 'c:\Northwind.bak'
with move 'Northwind'    to 'd:\microsoft sql server\mssql.1\mssql\data\Northwind.mdf'
    ,move 'Northwind_log' to 'd:\microsoft sql server\mssql.1\mssql\data\Northwind.ldf'
Northwind 數(shù)據(jù)庫在 SQL Server 2005 中順利還原。

注意,在 SQL Server 2005 中還原 Northwind 的時候,并不需要首先創(chuàng)建一個同名的 Northwind 數(shù)據(jù)庫,而是直接進行 restore。

另外的一個問題是,如果客戶給你一個 Northwind.bak 備份文件,讓你在自己的機器上 restore。那么如何來確定 with move 中的邏輯文件名呢?一個方法是向客戶咨詢獲取,二是使用 SQL Server restore filelistonly 來查看。

5. 使用 SQL Server restore filelistonly 命令來查看邏輯文件名
從 SQL Server restore filelistonly 命令結(jié)果中可以獲取很多信息,下面僅列出 LogicalName and PhysicalName。

restore filelistonly from disk='c:\Northwind.bak'
LogicalName      PhysicalName
---------------  ------------------------------------------------------------------
Northwind        d:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.mdf
Northwind_log    d:\Program Files\Microsoft SQL Server\MSSQL$SQLA\data\northwnd.ldf

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多