Question:
We have a SQL server 2005 database in a shared production environment. We do a backup of this database and want to restore it in a development environment having only a SQL-2005 Express Edition.
You cannot restore the prod database using the Management Studio Express.
What to do??
Answer:
You have to script the restoration. Do not create a database - it is done by the "Restore with move" command.
If you have already created a db and you want to restore into it, then try to use
RESTORE FROM DISK ="path_to_your_backup_file" WITH REPLACE
Here is a sample-script and some links we used.
Declare @newTargetDBName nvarchar(50) Declare @newTargetDataFileName nvarchar(255) Declare @newTargetLogFileName nvarchar(255) Declare @newTargetSysFTName nvarchar(255) Declare @restoredSourceFile nvarchar(255) Declare @restoredSourceLogicalDataFileName nvarchar(255) Declare @restoredSourceLogicalLogFileName nvarchar(255) Declare @restoredSourceLogicalSysFTName nvarchar(255) Set @newTargetDBName = 'mydbprod_20091208' Set @newTargetDataFileName = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mydbprod_20091208.mdf' Set @newTargetLogFileName = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mydbprod_20091208_log.ldf' Set @newTargetSysFTName = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\mydbprod_20091208_sysft' Set @restoredSourceFile = 'E:\ReleaseBackups\mydbprod_20091208.bak' Set @restoredSourceLogicalDataFileName = 'mydbprod' Set @restoredSourceLogicalLogFileName = 'mydbprod_log' Set @restoredSourceLogicalSysFTName = 'sysft_mydbprod' ----Restore Database RESTORE DATABASE @newTargetDBName FROM DISK = @restoredSourceFile WITH MOVE @restoredSourceLogicalDataFileName TO @newTargetDataFileName, MOVE @restoredSourceLogicalLogFileName TO @newTargetLogFileName, MOVE @restoredSourceLogicalSysFTName TO @newTargetSysFTName go
If you do not know the logical names of the production database you can query the .bak file.
RESTORE FILELISTONLY FROM DISK = 'E:\ReleaseBackups\mydbprod_20091208.bak' GO
Links:
Restore Database Backup using SQL Script by pinaldave
Restore on MSDN
.
No comments:
Post a Comment