Tuesday, July 15, 2008

Restore the SQL 2005 Database using script

The SQL 2005 management studio has wizard for restore the database. It works pretty good for most cases, but I found the scripting is much for flexible. Recently, I tried to restore a database to with a different name, but the wizard won't let me to do it. Here is the example of the alternative script way. It worked great for me.

Restore Database YourDBName
From Disk = 'TheBAKFileName.bak'
With Move 'MDFFileName' To 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\YourDBName.MDF',
Move 'LDFFileName_Log' To 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\YourDBName.ldf',
REPLACE

No comments: