newbie27
asked on
RESTORE DATABASE SYNTAX With log files
Hello Experts
I have extracted the database and now trying to restore the data to the new database which obviously has a different name
When I try to run the following statement I am getting ".mdf file cannot be over written"
Please can someoen advise?
Thanks
I have extracted the database and now trying to restore the data to the new database which obviously has a different name
When I try to run the following statement I am getting ".mdf file cannot be over written"
Please can someoen advise?
Thanks
-- original datbase name is stagesng, new db name is stage2sng
use master
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stagesng.bak'
WITH REPLACE
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sorry, used the below
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage sng.mdf',
MOVE 'stagesng_log' TO 'C:\sng\db\sngstage2\stage sng_log.LD F'
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage
MOVE 'stagesng_log' TO 'C:\sng\db\sngstage2\stage
ASKER
AngelIII
:
I have also tried using the full path but getting the same error as above
:
I have also tried using the full path but getting the same error as above
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stagesng.bak'
WITH MOVE 'C:\sng\db\stagesng.mdf' TO 'C:\sng\db\sngstage2\stage2sng.mdf',
MOVE 'C:\sng\db\stagesng_log.LDF' TO 'C:\sng\db\sngstage2\stage2sng_log.LDF'
does the folder:
C:\sng\db\sngstage2
exist? it has to, sql server restore will not create folders...
C:\sng\db\sngstage2
exist? it has to, sql server restore will not create folders...
ASKER
Yes this folder do exist C:\sng\db\sngstage2
then, please confirm that there is no other database which uses already those file names (apart the one your restore over), and if you do confirm, please post the exact and full error message.
ASKER
Yes, stage2sng.mdf and stage2sng.ldf are the files which I want to create for new database, there is no such file already exist
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'C:\sng\db\stagesng.mdf' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE 'C:\sng\db\stagesng_log.LD F' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF'
I am getting this error
Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'stage2sng' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'C:\sng\db\stagesng.mdf' TO 'C:\sng\db\sngstage2\stage
MOVE 'C:\sng\db\stagesng_log.LD
I am getting this error
Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'stage2sng' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Does the stage2sng database already exist? You may want to do a refresh.
The backup set holds a backup of a database other than the EXISTING 'stage2sng' database.
The backup set holds a backup of a database other than the EXISTING 'stage2sng' database.
ASKER
Hi,
Yes the database "stage2sng" already exist, which I have created just today and I want to restore data from the stagesng database. I hope this makes sense?
Thanks
Yes the database "stage2sng" already exist, which I have created just today and I want to restore data from the stagesng database. I hope this makes sense?
Thanks
Either delete stage2sng or add replace like so....
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'C:\sng\db\stagesng.mdf' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE 'C:\sng\db\stagesng_log.LD F' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF', REPLACE
Bear in mind this will overwrite the database.
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'C:\sng\db\stagesng.mdf' TO 'C:\sng\db\sngstage2\stage
MOVE 'C:\sng\db\stagesng_log.LD
Bear in mind this will overwrite the database.
ASKER
Thanks I have tried the above
Msg 3234, Level 16, State 2, Line 1
Logical file 'C:\sng\db\stagesng.mdf' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
obviously, stagesng.mdf is not part of the new database....
why it would not letting me restore this to stage2sng database.... ????
thanks
Msg 3234, Level 16, State 2, Line 1
Logical file 'C:\sng\db\stagesng.mdf' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
obviously, stagesng.mdf is not part of the new database....
why it would not letting me restore this to stage2sng database.... ????
thanks
logical file is the name of the data file, not the actual filename
if you write click on the database, go to properties, and go to files, you will see the name in there
it's probably stagesng.
if you write click on the database, go to properties, and go to files, you will see the name in there
it's probably stagesng.
I see the problem. Below there are sections which i have marked LOGICAL FILE NAME. If you check the original database properties under files you will see logical fileaname. Its will be something like "stagesng_data" & "stagesng_log". This is what need to be entered.
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE [LOGICAL FILE NAME]' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE '[LOGICAL FILE NAME]' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF', REPLACE
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE [LOGICAL FILE NAME]' TO 'C:\sng\db\sngstage2\stage
MOVE '[LOGICAL FILE NAME]' TO 'C:\sng\db\sngstage2\stage
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE 'stagesng_logF' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF', REPLACE
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage
MOVE 'stagesng_logF' TO 'C:\sng\db\sngstage2\stage
ASKER
OK, I have tried with this
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'stagesng.mdf' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE 'stagesng_log.LDF' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF', REPLACE
and this is the error
Msg 3234, Level 16, State 2, Line 1
Logical file 'stagesng.mdf' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'stagesng.mdf' TO 'C:\sng\db\sngstage2\stage
MOVE 'stagesng_log.LDF' TO 'C:\sng\db\sngstage2\stage
and this is the error
Msg 3234, Level 16, State 2, Line 1
Logical file 'stagesng.mdf' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
try this please
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage sng.bak'
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage 2sng.mdf',
MOVE 'stagesng_log' TO 'C:\sng\db\sngstage2\stage 2sng_log.L DF', REPLACE
RESTORE DATABASE stage2sng
FROM DISK = 'C:\sng\db\sngstage2\stage
WITH MOVE 'stagesng' TO 'C:\sng\db\sngstage2\stage
MOVE 'stagesng_log' TO 'C:\sng\db\sngstage2\stage
in the move section you still had your file extensions so it was failing. correct syntax is as above (ensuring you got your logical names correct.
look at the original database properties and have a look at the attatched screenshot. This outlines the logical name location.
dbprop.bmp
dbprop.bmp
ASKER
Tried Humpdy, still getting the same error
Msg 3234, Level 16, State 2, Line 1
Logical file 'stagesng' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Msg 3234, Level 16, State 2, Line 1
Logical file 'stagesng' is not part of database 'stage2sng'. Use RESTORE FILELISTONLY to list the logical file names.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
ok, then you have your logical name wrong, you need to look at the properties to get your logical names correct, as posted above by EvilPostIt
or you can use this query to get your logical file names for your data and transaction files.
select name from sys.sysfiles
select name from sys.sysfiles
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
EvilPostIt:
That is it ! thank you very much, I was using wrong logical names ...
When I run the backup, it created stagesng.mdf and stagesng.log files and I was using these file names, but when I looked into their original logical names they were something like sng6 and sng6_log
It looks like it has restored the db ...
thank you again for the help folks !
That is it ! thank you very much, I was using wrong logical names ...
When I run the backup, it created stagesng.mdf and stagesng.log files and I was using these file names, but when I looked into their original logical names they were something like sng6 and sng6_log
It looks like it has restored the db ...
thank you again for the help folks !
No probs.
ASKER
i have used the below and got the error attached
Msg 3154, Level 16, State 4, Line 1
The backup set holds a backup of a database other than the existing 'stage2sng' database.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
please can you advise?
Open in new window