patternsqlMinor
Move (Restore) SQL Server 2005 database which does not exist before
Viewed 0 times
sqlwhichexistmovedatabase2005doesserverbeforenot
Problem
I did not ready about this but found out after trying to restore a database from remote server and it wont restore if the database did not exist before. What I would do is
It will give me error. I think I found it almost accidently (or out frustration, just restored it on top of the database, and it worked).
Now as I am typing the question, I realize move is probably not the same thing as restore. For restore, the database must already exist?
I am in the same position again to restore a database which does not exist on my system.
Am I missing anything? I would like to know, what are the rules when restoring (or moving) the database.
Edit : Adding the dialog error. I just repeated the process. I am not sure this was the exact error I was getting before. I renamed the original db that I have. Then I import using SSMS.
- create a .bak file (backup the database)
- Copy the .bak file to the remote server using shared folder
- Run restore in SQL Server Management Studio to restore the database
It will give me error. I think I found it almost accidently (or out frustration, just restored it on top of the database, and it worked).
Now as I am typing the question, I realize move is probably not the same thing as restore. For restore, the database must already exist?
I am in the same position again to restore a database which does not exist on my system.
- What procedure do I follow?
- Do I need to set permission on the .bak file before restoring successfully on remote Server?
- Or is there a better way?
Am I missing anything? I would like to know, what are the rules when restoring (or moving) the database.
Edit : Adding the dialog error. I just repeated the process. I am not sure this was the exact error I was getting before. I renamed the original db that I have. Then I import using SSMS.
Solution
No, for a restore you don't have to have the database existing already (be mindful though to not have the
The below statement would create a new database from the backup:
Obviously, modify the parameters accordingly. But this doesn't require
with replace option set in your restore database command).The below statement would create a new database from the backup:
RESTORE DATABASE [YourNewDbName]
FROM DISK = N'C:\YourBackupFile.bak'
WITH FILE = 1,
MOVE N'YourDataFile' TO N'C:\YourNewDbName.mdf',
MOVE N'YourLogFile' TO N'C:\YourNewDbName_1.ldf',
NOUNLOAD,
STATS = 10
GOObviously, modify the parameters accordingly. But this doesn't require
YourNewDbName to exist prior to the restore database.Code Snippets
RESTORE DATABASE [YourNewDbName]
FROM DISK = N'C:\YourBackupFile.bak'
WITH FILE = 1,
MOVE N'YourDataFile' TO N'C:\YourNewDbName.mdf',
MOVE N'YourLogFile' TO N'C:\YourNewDbName_1.ldf',
NOUNLOAD,
STATS = 10
GOContext
StackExchange Database Administrators Q#14849, answer score: 6
Revisions (0)
No revisions yet.