Import .bak file to a database in SQL server

2020-02-16 05:45发布

I have a file with .bak extension.

How can I import this date to a database in SQL Server?

9条回答
成全新的幸福
2楼-- · 2020-02-16 06:09
  1. Connect to a server you want to store your DB
  2. Right-click Database
  3. Click Restore
  4. Choose the Device radio button under the source section
  5. Click Add.
  6. Navigate to the path where your .bak file is stored, select it and click OK
  7. Enter the destination of your DB
  8. Enter the name by which you want to store your DB
  9. Click OK

Done

查看更多
啃猪蹄的小仙女
3楼-- · 2020-02-16 06:10

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/

查看更多
The star\"
4楼-- · 2020-02-16 06:12
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'
查看更多
放我归山
5楼-- · 2020-02-16 06:14

Simply use

sp_restoredb 'Your Database Name' ,'Location From you want to restore'

Example: sp_restoredb 'omDB','D:\abc.bak'

查看更多
smile是对你的礼貌
6楼-- · 2020-02-16 06:18

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

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

查看更多
够拽才男人
7楼-- · 2020-02-16 06:23
  1. Copy your backup .bak file in the following location of your pc : C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\DATA
  2. Connect to a server you want to store your DB
  3. Right-click Database
  4. Click Restore
  5. Choose the Device radio button under the source section
  6. Click Add.
  7. Navigate to the path where your .bak file is stored, select it and click OK
  8. Enter the destination of your DB
  9. Enter the name by which you want to store your DB
  10. Click OK

The above solutions missed out on where to keep your backup (.bak) file. This should do the trick. It worked for me.

查看更多
登录 后发表回答