Restore database in SQL Server 2005

空扰寡人 提交于 2019-12-07 02:02:33

You need to specify where to store the physical files when you restore a .bak if your target server doesn't have the same disk/directory layout as the original source server. The backup file contains the logical SQL Server files along with the original location on the source server (the full physical path where the .mdf and .ldf where located).

So you need to use something like this:

RESTORE DATABASE [MPRM] 
FROM DISK = N'\\rauf\shared\MPRM_15_5_10.BAK' 
WITH FILE = 1,  
MOVE N'MPRM' TO N'D:\MSSQL\Data\MPRM.mdf',  
MOVE N'MPRM_Log' TO N'D:\MSSQL\Data\MPRM_Log.ldf',  
NOUNLOAD, REPLACE,  
STATS = 10

This command here:

MOVE N'MPRM' TO N'D:\MSSQL\Data\MPRM.mdf',  

specifies that the logical file called MPRM (that's the default when you didn't specify anything else when creating your SQL Server database) should be moved during restore to the physical location D:\MSSQL\Data\MPRM.mdf (adapt this as needed)

To just see what is contained inside a backup file, you can use this command here:

RESTORE FILELISTONLY
FROM DISK = N'\\rauf\shared\MPRM_15_5_10.BAK' 

This will show you all the logical files inside your backup, along with their original physical file that they were backed up from (on the source server, where you ran the backup command).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!