SQL – How to restore a database backup to a different location

You may be required to restore a database backup to a location different from the location of the original backup. If you backed up with a password then this will need to be done programmatically.

The following example shows how to use a backup taken from a database called Database and restore it to a new location on a new server with the name Database2.

RESTORE DATABASE [NEW_DATABASE]
FROM  DISK = N’\\NETWORK_STARAGE_LOCATION\database.BAK’
WITH  password = ‘password’,
FILE = 1, 
MOVE N’database’ TO N’C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\database2.mdf’, 
MOVE N’database_log’ TO N’C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\DATA\database2.log, 
NOUNLOAD,  STATS = 10
GO

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s