Restore Database From Backup File (From 2005 to 2016 )Posted: June 12, 2017
You can restore a full backup file taken from an early SQL Server to current SQL Server 2016 instance with either T-SQL code or through SSMS.
Please check the code sample and the steps to use SSMS:
--Get database logicalNames restore filelistonly from disk='C:\mssql\mydatabase2005.BAK' --mydatabase --mydatabase_Log ---Restore to a new database RESTORE DATABASE myDB2016 FROM DISK = N'C:\mssql\mydatabase2005.BAK' WITH MOVE N'mydatabase' TO N'C:\mssql\myDB2016.mdf', MOVE N'mydatabase_Log' TO N'C:\mssql\myDB2016_Log.ldf', REPLACE; GO ---Get the logical names of the new database select name as logicalname from sys.master_files where DB_NAME(database_id)='myDB2016' --result: --mydatabase --mydatabase_Log -- Rename logical names to new names at your choice ALTER DATABASE myDB2016 MODIFY FILE (NAME = 'mydatabase', NEWNAME = 'MyDB2016_data') GO ALTER DATABASE MyDB2016 MODIFY FILE (NAME = 'mydatabase_Log', NEWNAME = 'MyDB2016_log') GO --Check out the new names select name, physical_name from sys.master_files where DB_NAME(database_id)='myDB2016'
From SSMS,you need to right-clcik on Databases>>Restore From Files and Filegroups>> type a new database name To database box and choose From device to point to the backup file we want to restore. And check the full backup from the list and click on Ok. Your new database will be ready after the restore finished.
If you have already had a database you want to replace, you need to go to Options page to check the Overwrite the existing database option (WITH REPLACE T-SQL cod), click OK and it is done. Your old database has been replaced with this one.
Your restore database will have the same logical names it has in the database the backup was taken.
You can change the names from Properties>> Files >> type new Logical names and click OK.
You can use the Script choice to view the code for your action:
Here is T-SQL code generated by SSMS:
USE [myDB2016] GO ALTER DATABASE [myDB2016] MODIFY FILE (NAME=N'mydatabase', NEWNAME=N'MyDB2016_data') GO USE [myDB2016] GO ALTER DATABASE [myDB2016] MODIFY FILE (NAME=N'mydatabase_log', NEWNAME=N'MyDB2016_log') GO