Solved

Creating A Database copy via RESTORE WITH MOVE

Posted on 2009-07-14
4
512 Views
Last Modified: 2012-05-07
Hey everyone,

I'm trying to create a copy of an MSSQL database with the RESTORE WITH MOVE command.  Please find below the code I am running in my futile attempts ( database names have been changed to protect the innocent ).

I expect to see a new database called NewDatabase on my server containing all data from OldDatabase.  Instead, I get:

Changed database context to 'OldDatabase'.

Query OK, -1 rows affected (234 ms)

Query OK, -1 rows affected (468 ms)

Changed database context to 'master'.

Query OK, -1 rows affected (249 ms)

Query OK, -1 rows affected (249 ms)

and no new database.


USE OldDatabase
 
BACKUP DATABASE OldDatabase
TO DISK = 'C:\backups\7-14.bak'
   WITH NAME = 'Full Backup of OldDatabase 7-14';
GO
 
USE master
 
RESTORE DATABASE NewDatabase
 
FROM DISK = 'C:\backups\7-14.bak'
 
WITH MOVE 'OldDatabase' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\NewDatabase.mdf',
MOVE 'OldDatabase_Log'  TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\NewDatabase_log.ldf',
     REPLACE 
GO
;

Open in new window

0
Comment
Question by:sellcenter
  • 3
4 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24851938
Have you considered refreshing?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24851947
Perhaps I should have been clearer:
1. Click on the Databases object.
2, Press F5
0
 

Accepted Solution

by:
sellcenter earned 0 total points
ID: 24864559
I've found the solution.  I need to add a "GO" on line 2 in the above code.
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 24865435
With all due respect, that makes no sense whatsoever.  But whatever works for you.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Character matching different date formats for dates between 6 46
How to share SSIS Package? 6 37
replace \ by - in select 4 21
divide by zero error 23 16
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question