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.
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 |
|
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 |
|
|
|
|
|