Import .bak file to a database in SQL server Import .bak file to a database in SQL server sql-server sql-server

Import .bak file to a database in SQL server


On SQL Server Management Studio

  1. Right click Databases on left pane (Object Explorer)
  2. Click Restore Database...
  3. Choose Device, click ..., and add your .bak file
  4. Click OK, then OK again

Done.


.bak files are database backups. You can restore the backup with the method below:

How to: Restore a Database Backup (SQL Server Management Studio)


This will show you a list of database files contained in DB.bak:

RESTORE FILELISTONLY FROM DISK = 'D:\3.0 Databases\DB.bak' 

You will need the logical names from that list for the MOVE operation in the second step:

RESTORE DATABASE YourDBFROM DISK = 'D:\3.0 Databases\DB.bak' 

and you have to move appropriate mdf,ndf & ldf files using

With Move 'primarydatafilename' To 'D:\DB\data.mdf', Move 'secondarydatafile' To 'D:\DB\data1.ndf', Move 'logfilename' To 'D:\DB\log.ldf'