I have a file with .bak
extension.
How can I import this date to a database in SQL Server?
Done
Simply use
sp_restoredb 'Your Database Name' ,'Location From you want to restore'
Example: sp_restoredb 'omDB','D:\abc.bak'
Instead of choosing Restore Database..., select Restore Files and Filegroups...
Then enter a database name, select your .bak file path as the source, check the restore checkbox, and click Ok. If the .bak file is valid, it will work.
(The SQL Server restore option names are not intuitive for what should a very simple task.)
The above solutions missed out on where to keep your backup (.bak) file. This should do the trick. It worked for me.
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 YourDB
FROM 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'
.bak files are database backups. You can restore the backup with the method below:
How to: Restore a Database Backup (SQL Server Management Studio)