Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 SQL Server Administration (2005)
 Restoring a database with move with replace

Author  Topic 

lorengd
Starting Member

2 Posts

Posted - 2011-01-20 : 14:35:21
Good morning,

I have the following code for restoring a database with move, but sometimes it needs to replace a database in the location that it's moving to. How would I change this to add a with replace?
SET @SQL = 'RESTORE DATABASE %database% FROM DISK = ''%destination%\%backup%'' WITH MOVE '''
SET @SQL = @SQL + @LogicalNameData + ''' TO ''D:\MSSQL\Data\%database%_Data.MDF'', MOVE ''' + @LogicalNameLog + ''' TO '
SET @SQL = @SQL + '''D:\MSSQL\Data\%database%_Log.LDF'''

Thanks

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2011-01-20 : 14:52:29
http://weblogs.sqlteam.com/tarad/archive/2005/11/08/8262.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

lorengd
Starting Member

2 Posts

Posted - 2011-01-20 : 16:09:06
So would this work:
SET @SQL = 'RESTORE DATABASE %database% FROM DISK = ''%destination%\%backup%'' WITH REPLACE, MOVE '''
SET @SQL = @SQL + @LogicalNameData + ''' TO ''D:\MSSQL\Data\%database%_Data.MDF'', MOVE ''' + @LogicalNameLog + ''' TO '
SET @SQL = @SQL + '''D:\MSSQL\Data\%database%_Log.LDF'''

Thanks
Go to Top of Page
   

- Advertisement -