Link to home
Start Free TrialLog in
Avatar of GentooOS
GentooOS

asked on

Need To Restore Database And Transaction Log Using Query Analyzer

Using only Query Analyzer I'd like to restore a database and logs to a new database on the same server.  The backups are .BAK and .TRN files located on the same server. How do I do this?  What is the syntax?
Avatar of Kevin Hill
Kevin Hill
Flag of United States of America image

See Books Online topic RESTORE DATABASE and RESTORE LOG in Books Online....

Assuming MyNWind already exists and is your source db...


RESTORE DATABASE MyNwind_New
   FROM MyNwind_1 --change to physical file location if necessary
   WITH NORECOVERY,
      MOVE 'MyNwind' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\NewNwind.mdf',
      MOVE 'MyNwindLog1' TO 'c:\Program Files\Microsoft SQL Server\MSSQL\Data\NewNwind.ldf'

RESTORE LOG MyNwind
   FROM MyNwindLog1 --change to physical file location if necessary
   WITH RECOVERY

Avatar of GentooOS
GentooOS

ASKER

I must be messing up the physical file locaton or syntax but it is not working.

Can you give an example if the old database name is db_old and the new one is db_new.     db_old files are c:\program files\database\db_old\db_old.mdf and log file is db_old_log.ldf in the same location.  Backups would be c:\program files\database\backups\db_old\db_old.bak and db_old.trn

Thanks.
ASKER CERTIFIED SOLUTION
Avatar of Kevin Hill
Kevin Hill
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I get this:

Server: Msg 3234, Level 16, State 2, Line 1
Logical file 'db_old' is not part of database 'db_new'. Use RESTORE FILELISTONLY to list the logical file names.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Post your exact sql statement please...
RESTORE DATABASE PCMS_New FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\ERIE_PCMS_INIT\ERIE_PCMS_INIT_db_200504151209.BAK'
WITH NORECOVERY,
MOVE 'ERIE_PCMS_INIT' TO 'c:\new.mdf',
MOVE 'ERIE_PCMS_INIT_log' TO 'c:\new_log.ldf'



Server: Msg 3234, Level 16, State 2, Line 1
Logical file 'ERIE_PCMS_INIT' is not part of database 'PCMS_New'. Use RESTORE FILELISTONLY to list the logical file names.
Server: Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally.
Go into the properties of the old db currently on the server through Enterprise Manager and get the logical file names for the data and log files...
Why does the current location matter?  I'm restoring from at backup.

Thery are here:

C:\PCMS\ERIE_PCMS\ERIE_PCMS_INIT_Data.MDF
C:\PCMS\ERIE_PCMS\ERIE_PCMS_INIT_Log.LDF
I was looking for the logical file names, not the loation of the physical files.  Its the first column in the "data files" and "transaction log" tabs (i.e. Pubs and Pubs_log)
OK. the name was different under data files from the name of the database.  Thanks that did the trick.