Restoring MSSQL database files to different names, location.

Sometimes you’ll want to restore a database to a different name.

Here’s now you can get the filelist and also change the destination location.

Get the DB File List

RESTORE FILELISTONLY FROM DISK= N'path of backup file'

Restore to a different location

ALTER DATABASE databasename SET SINGLE_USER WITH ROLLBACK IMMEDIATE;

GO

RESTORE DATABASE databasename

FROM DISK= 'path of backup file'

WITH REPLACE,

MOVE 'Logical DB Name' TO 'new DB file location (with filename).mdf',

MOVE 'Logical Log Name' TO 'new log file location (with filename).log';

GO

ALTER DATABASE databasename SET MULTI_USER;

GO