Brian's Blog

items I see across my tribes

SQL Server: Restore Database

September 04
by briancarter 4. September 2010 08:05

image[1] Another approach to SQL Server backup and restore, aside from using Enterprise Manager, is to use T-SQL commands. Enterprise Manager can be a quick and easy way to run backups or restores, but T-SQL offers a lot more flexibility. With T-SQL you can script your backups or script to restore several backup files.

As a developer, a quick and easy way to backup & restore is essential; especially after hours when your in a hurry to get it done and go home.

My typical process is to restore to another db.  Create a new database to use as a holding spot for the restore (PondWaterEAVRestore).  It can be restored to your backup using following TSQL:

Restore: Retrieve the Logical file name of the database from SSMS.  With this example, the ndf will also be restored and associated with the db:

 

To get the name of the logical files and where it expects to put them you 

can use:

RESTORE FILELISTONLY
FROM DISK =
'c:\_sql\backup\pondwater.bak'
GO

 

If you are using Godaddy, create the database locally and add in another file with prefix ‘sysft’.  Then you can copy your backup file from your Godaddy server to your local box and do a restore:

restore database Pondwater
from disk = 'c:\_sql\backup\pondwater.bak'
with REPLACE,
MOVE 'pondwater' TO 'C:\_SQL\pondwater.mdf',
MOVE 'sysft_pondwater' TO 'C:\_SQL\sysft_pondwater.ndf',
MOVE 'pondwater_log' TO 'C:\_SQL\pondwater_log.ldf'

 

Categories: Development

Comments


 Questions or Feedback, my contact information is located on my About page.


The opinions, thoughts, and comments made in these blog posts are solely my own (unless otherwise stated). They do not reflect the opinions, thoughts or practices of my employer, my universities, my family, or anyone else. Also, I retain the right to change my mind about anything I publish here without having to go back and edit posts that occurred in the past. 

These are my opinions, or just as likely, someone else's opinions that I leveraged for my own.