restore DB from bak file

Winston TheFifth 101 Reputation points

I have a database, DB1. I want to create a 2nd DB from the bak file from DB1 to compare the DB at that time to the current DB1. Is this possible? How? When I create a 2nd DB called DB2 and try to restore from the bak file from Db1 it fails.

SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,262 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Dillon Silzer 52,736 Reputation points

    Have you tried following the guide below by Charanjeet Kaur? Pay attention closely to detail from Steps 7 and on.

    If you have any questions please ask. If this has helped you please mark as an answer.

  2. Erland Sommarskog 98,911 Reputation points

    Use this command:

       RESTORE DATABASE DB2 FROM DISK = 'C:\temp\DB1.bak'  
       WITH MOVE 'DB1' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DB.ldf',  
           MOVE 'DB1_log' 'C:\Program Files\Microsoft SQL Server\MSSQL15.MSSQLSERVER\MSSQL\DB2.1df'  

    Replace C:\temp\DB1.bak with the actual path to the backup. In the strings that follow MOVE replace DB1 with your database name. Now, there is nothing that says that these names have to follow that pattern, but it is quite common that they do. You can use


    to find out what the actual names are.

    If you get any error messages, please share them with us.

  3. CathyJi-MSFT 21,111 Reputation points Microsoft Vendor

    Hi @Winston TheFifth ,

    If you using SSMS UI to restore DB1 backup to DB2, please note below key points. If it still failed, please share us the detail error message from SSMS UI by clicking the message beside red X in lower left corner, or get the detail error message from SQL server error log.

    If you using T-SQL to complete this job, please refer to below T-SQL; Please change the location of .bak to the correct one in your environment.

    1.Determine the logical file names of the database, from the backup file, along with their physical paths by executing the RESTORE FILELISTONLY command:

    use DB1  
    RESTORE FILELISTONLY FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\Backup\DB1.bak'  


    check physical path of DB2

    use DB2  
      name 'Logical Name',   
      physical_name 'File Location'  
    FROM sys.database_files  


    2.Restore database.

    use master  
    RESTORE DATABASE DB2 FROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\Backup\DB1.bak'  
    MOVE N'DB1' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\DATA\DB2.mdf',  
    MOVE N'DB1_log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL15.SQL2019\MSSQL\DATA\DB2.ldf';  


    If it still does not work, please share us the error message for analysis.

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments