现在的位置: 首页 > 综合 > 正文

用SQL语句恢复备份到新数据库

2012年08月28日 ⁄ 综合 ⁄ 共 925字 ⁄ 字号 评论关闭

RESTORE DATABASE YourDB2  /* YourDB2 新数据库*/
from disk='D:/YourDB1_backup_200807141721.bak'  /* YouerDB1的备份文件*/
with

move 'YourDB1_Data'  to 'D:/Invoice/db/YourDB1_200807141721_Data.mdf',
move 'YourDB1_Log'  to 'D:/Invoice/db/YourDB1_200807141721_Log.ldf'Replace

REPLACE

Specifies that SQL Server should create the specified database and its related files even if another database already exists with the same name. In such a case, the existing database is deleted. When the REPLACE option is not specified, a safety check occurs (which prevents overwriting a different database by accident). The safety check ensures that the RESTORE DATABASE statement will not restore the database to the current server if:

  1. The database named in the RESTORE statement already exists on the current server, and
  2. The database name is different from the database name recorded in the backup set.

REPLACE also allows RESTORE to overwrite an existing file which cannot be verified as belonging to the database being restored. Normally, RESTORE will refuse to overwrite pre-existing files.

 

抱歉!评论已关闭.