问题
I have a file with .bak
extension.
How can I import this date to a database in SQL Server?
回答1:
On SQL Server Management Studio
- Right click Databases on left pane (Object Explorer)
- Click Restore Database...
- Choose Device, click ..., and add your .bak file
- Click OK, then OK again
Done.
回答2:
.bak files are database backups. You can restore the backup with the method below:
How to: Restore a Database Backup (SQL Server Management Studio)
回答3:
RESTORE FILELISTONLY
FROM DISK = 'D:\3.0 Databases\DB.bak'
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'
回答4:
You can simply restore these database backup files using native SQL Server methods, or you can use ApexSQL Restore tool to quickly virtually attach the files and access them as fully restored databases.
Disclaimer: I work as a Product Support Engineer at ApexSQL
回答5:
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.)
回答6:
- Connect to a server you want to store your DB
- Right-click Database
- Click Restore
- Choose the Device radio button under the source section
- Click Add.
- Navigate to the path where your .bak file is stored, select it and click OK
- Enter the destination of your DB
- Enter the name by which you want to store your DB
- Click OK
Done
回答7:
Simply use
sp_restoredb 'Your Database Name' ,'Location From you want to restore'
Example: sp_restoredb 'omDB','D:\abc.bak'
回答8:
- Copy your backup .bak file in the following location of your pc : C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
- Connect to a server you want to store your DB
- Right-click Database
- Click Restore
- Choose the Device radio button under the source section
- Click Add.
- Navigate to the path where your .bak file is stored, select it and click OK
- Enter the destination of your DB
- Enter the name by which you want to store your DB
- Click OK
The above solutions missed out on where to keep your backup (.bak) file. This should do the trick. It worked for me.
回答9:
You can use node package, if you often need to restore databases in development process.
Install:
npm install -g sql-bak-restore
Usage:
sql-bak-restore <bakPath> <dbName> <oldDbName> <owner>
Arguments:
- bakpath, relative or absolute path to file
- dbName, to which database to restore (!! database with this name will be deleted if exists !!)
- oldDbName, database name (if you don't know, specify something and run, you will see available databases after run.)
- owner, userName to make and give him db_owner privileges (password "1")
!! sqlcmd command line utility should be in your PATH variable.
https://github.com/vladimirbuskin/sql-bak-restore/
来源:https://stackoverflow.com/questions/1535914/import-bak-file-to-a-database-in-sql-server