Solved

Creating A Database copy via RESTORE WITH MOVE

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

743 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

13 Experts available now in Live!

Get 1:1 Help Now