Import .bak file to a database in SQL server

前端 未结 12 1752
悲哀的现实
悲哀的现实 2020-12-22 17:51

I have a file with .bak extension.

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

相关标签:
12条回答
  • 2020-12-22 18:05
    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

    0 讨论(0)
  • 2020-12-22 18:07

    Simply use

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

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

    0 讨论(0)
  • 2020-12-22 18:10

    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.)

    0 讨论(0)
  • 2020-12-22 18:10
    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.

    0 讨论(0)
  • 2020-12-22 18:15

    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'
    
    0 讨论(0)
  • 2020-12-22 18:16

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

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

    0 讨论(0)
提交回复
热议问题