Solved

Creating A Database copy via RESTORE WITH MOVE

Posted on 2009-07-14
4
511 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now