Link to home
Start Free TrialLog in
Avatar of emi_sastra
emi_sastra

asked on

Restore MS SQL database to diferent name.

Hi All,

I try to restore MS SQL database using SSMS.

Saya I want to restore from ERV_GL to KKP_GL.
What I do :

1. Create database KKP_GL
2. Restore from ERV_GL.BAK at database KKP_GL

The problem is ERV_GL also get restore.

What is the problem?
How to solve this problem?

Thank you.
Avatar of Raja Jegan R
Raja Jegan R
Flag of India image

If you are doing it via SSMS, then try the below steps:
1. Right click KKP_GL database
2. Choose Tasks -> Restore -> Database
3. Choose Device -> Select your *.bak file.
4. Click on Options tab and choose Overwrite the existing database..
Hi,

I want to ask: Which version of SQL? Which version of SSMS?

So here are some steps in SSMS
I've created a database erv_gl with a table dbo.GL with some data.
I've taken a backup
I add some additional data not in the backup
Right + Click on Databases (in Object Explorer) and select Restore database
Source is ERV_GL
Destination is KKP_GL
Select option of overwrite
Click OK

I confirm that the table is in KKP_GL, with the data from before the backup only.

I confirm that the table is in ERV_GL with the additional data.

Does that help?

If you had scripted the database restore, you wouldn't have to create KKP_GL first as a separate step.

HTH
  David
Avatar of emi_sastra
emi_sastra

ASKER

The problem is the log file name conflict with ERV_GL.
It does not rename to KKP_GL

Thank you.
ERV_GL shows restoring.

Thank you.
>> The problem is the log file name conflict with ERV_GL.

If that is the case, after step 3 above, click on Files and rename the files so that it won't conflict with the older ones or ERV_GL database..
>> ERV_GL shows restoring.

May I know whether you have did anything to ERV_GL database..
The best way to solve the problem is to never use the gui to do a database restore.  Use a restore command instead.  Then, if you have to do a similar restore next week or in 6 months, you can easily and accurately update the script and not have to guess your way thru the gui again.

You'll need to get the logical file names for the db.  You can do that using this command:
EXEC ERV_GL.sys.sp_helpfile
The first column contains the logical names.

--Add a MOVE clause for every logical file in the db, using the logical file name above and the physical location where you want the file to end up.  For example:

RESTORE DATABASE KKP_GL
FROM DISK = 'x:\full\path\to\backup\file\backup.bak'
WITH MOVE 'KKP_GL' TO 'd:\full\path\to\data\file\KKP_GL.mdf',
    MOVE 'KKP_GL_LOG' TO 'l:\full\path\to\log\file\KKP_GL_lod.ldf'
Hi,

Like Scott says, I always script my restores.

Looking at the syntax there for a moment, I'm wondering if you'll need the replace option like this

RESTORE DATABASE KKP_GL
FROM DISK = 'x:\full\path\to\backup\file\backup.bak'
WITH
    replace
    , MOVE 'KKP_GL' TO 'd:\full\path\to\data\file\KKP_GL.mdf'
    , MOVE 'KKP_GL_LOG' TO 'l:\full\path\to\log\file\KKP_GL_lod.ldf'

If its to create a new database possibly not. If its to overwrite an existing database, more than likely definitely needed.

HTH
  David
, MOVE 'KKP_GL' TO 'd:\full\path\to\data\file\KKP_GL.mdf'
    , MOVE 'KKP_GL_LOG' TO 'l:\full\path\to\log\file\KKP_GL_lod.ldf'

why move the same name ? should be :

   , MOVE 'ERV_GL' TO 'd:\full\path\to\data\file\KKP_GL.mdf'
    , MOVE 'ERV_GL_LOG' TO 'l:\full\path\to\log\file\KKP_GL_lod.ldf'

Thank you.
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.