Table of Content
    SQL Database Repair

    3 Methods to Attach SQL Database without Transaction Log File


    Table of Content

      Summary: Are you looking for a way to attach an SQL Server .MDF (primary database) file without transaction log file? This blog demonstrates different methods to attach a SQL db without the log file. If the MDF file you want to attach is corrupt or inaccessible, try using Stellar Repair for MS SQL software to repair the file.

      When the transaction log file (.ldf) is missing or corrupted, and you only have the .MDF file to restore SQL database; moreover, when there’s no backup available, you can attempt to attach the database file (.MDF) to SQL Server.

      How to Attach an SQL Database without the Log File?

      Following are 3 methods you can use to attach Microsoft SQL database without using the transaction log:

      Tip: To attach the database in SQL Server, you will need membership of the db_owner role.

      1. Using SQL Server Management Studio in SQL Server
      2. Using T-SQL Script
      3. Using Stellar Repair for MS SQL software

      Note: Method 1 and Method 2 will only work if the database had a clean shutdown (i.e., there were no active transactions while the database is shut down) and the MDF file is in a healthy state.

      Method #1: Using SQL Server Management Studio (SSMS)

      Step 1: Open SSMS, right-click on the Database node in the Object Explorer window and then click Attach.

      Attach Option
      Figure 1 – Attach Option in SSMS

      Step 2: In the Attach Databases window, click the Add button to specify the database you want to attach.

      Add Database
      Figure 2 – Add a SQL Database in SSMS

      Step 3: When the ‘Locate Database Files’ dialog box opens, browse through the path where .mdf database file is located, select the file, and then click on OK. A new LDF file will be created by SQL Server while attaching the SQL database. The database will now appear in Databases.

      Select MDF File
      Figure 3 – Select MDF File in SSMS

      Step 4: Now, return to the Attach Databases window. Under ‘Database details’, you will notice that the SQL Server cannot find the LDF file.

      Remove Log File Option in SSMS
      Figure 4 – Remove Log File Option in SSMS

      Step 5: To attach MDF without LDF file, select the transaction log file (.ldf), and then click on Remove.

      Executing these steps will attach an SQL database without the log file.

      Method #2: Using Transact-SQL

      You can also attach the database to SQL Server using T-SQL when the transaction log is missing. This procedure can be accomplished by using the following defined script where you need to mention the database’s name:

      CREATE DATABASE testdb ON
      (FILENAME = ‘C:\Program Files\Microsoft SQL Server..\MSSQL\DATA\testdb.mdf’)
      For ATTACH_REBUILD_LOG
      GO

      Note: Replace the ‘testdb.mdf’ in the above example with your MDF file.

      Execute DBCC CHECKDB

      When the MDF file is successfully attached to the SQL Server with a missing transaction log file (LDF), you must execute DBCC CHECKDB for a consistency check, i.e., for checking logical and physical integrity or errors in all the database components.

      Method #3: Using Stellar Repair for MS SQL

      The above methods won’t work if the MDF file you want to attach is corrupted. In that case, having an MDF database file repair tool, such as Stellar Repair for MS SQL at your disposal can help you scan and repair the MDF file.

      Stellar

      Once the master database file is repaired, you can use it to attach the SQL database without transaction log-file using either SSMS or executing a query in Transact-SQL.

      Read this: How to Repair MDF File?

      Key Features of Stellar Repair for MS SQL Software

      • Recovers all SQL database file components, including tables, keys, rules, indexes, defaults, stored procedures, etc.
      • Recovers deleted records from an MDF file.
      • Allows saving the repaired database components in multiple file formats, including XLS, HTML, CSV, and New Database or Live Database.
      • Supports SQL Server 2019, 2017, 2016, 2014, 2012, 2008, 2008 (R2).
      • The software is tested and recommended by Microsoft MVPs across the globe. The independent file formats allow accessing database contents without connecting to the Server environment. With the tool’s help, you can also gain access to database contents saved in the secondary database files.

      Hear what SQL MVP ‘Daniel Calbimonte’ has to say about Stellar SQL Database Repair Software.

      Conclusion

      This blog discussed several different ways to attach the MS SQL Server database without log file’. When connected to an instance of SQL Server, attach database without transaction log file using SQL Server Management Studio (SSMS). Or, you can use Transact-SQL (T-SQL) to attach the db to the server. But, if the MDF file is lost or corrupt, try using Stellar Repair for MS SQL software to repair the file and restore SQL database.

      Was this article helpful?

      No NO

      About The Author

      Bharat Bhushan linkdin

      Bharat Bhushan is an experienced technical Marketer working at Stellar Data Recovery - expertise in data care. He is skilled in Microsoft Exchange Database, MSSQL Database troubleshooting & data warehousing. He is a Management Post Graduate having a strong grip in Technology & certified in SAP-SD, Oracle 10g & Informatica Powercenter 9.1.

      24 comments

      1. I use these methods since 2014. But, I have never used software earlier.

        Can I try this tool without sharing credit card details?

        1. SQL Server Management Studio in SQL Server is a safe approach. But, I suggest execution of this method under the observation of experienced database experts.

      2. In my case, I have the log file, but the database was not working. I checked the log file and found the wrong name of my log file. I rename it so; the file used to work for me.

      3. Sir,

        I have my friend’s database, and he has no idea about the data. I think that that database is improperly detached. Both MDF and LDF files are present. When I am trying to attach the database then getting the following error

        “Could not continue scan with NOLOCK due to data movement. Converting database ‘Mydatabasename’ from version 539 to the current version 655. Database ‘Mydatabasename’ running the upgrade step from version 539 to version 551. (Microsoft SQL Server, Error: 601)”

        How can I attach my database in this situation?

        1. Noah,

          It is the sign of corruption. First, make a copy of your file and try any action on it.
          As you have ldf file then you can also try this:

          CREATE DATABASE [Yourdatabasename]
          ON (FILENAME=”C:\your mdf file location\mdffile.mdf”)

          You can try to attach your database without LDF file from the above-mentioned methods.

      4. Hello Jyoti,

        I ran the command of the second option with FOR ATTACH_REBUILD_LOG and fixed the issue. It will attempt to recreate the new empty log file for the database.

      5. Hello Jyoti,

        My database got corrupted, I run the DBCC command with the REPAIR_FAST AND REPAIR_REBUILD options, but the error remains. It was a creepy situation. Stellar Repair for MS SQL helped to repair my corrupt database.

      6. Hi Jyoti,

        It became easy for me to follow the steps because of images. I am a newbie so attaching the MDF file using SSMS option is easy and helpful.

      7. Greetings,

        This is the first time when I enjoyed the database repairing. No wonder to say this tool works on corrupt MDF file.
        Thanks for saving my data and my time.

      8. I have found this post brainstorming. I think it’s a perfect solution for all users who don’t have the log file. You mentioned all small points related to this issue.

      Leave a comment

      Your email address will not be published. Required fields are marked *

      Image Captcha
      Refresh Image Captcha

      Enter Captcha Here :

      Related Posts

      WHY STELLAR® IS GLOBAL LEADER

      Why Choose Stellar?

      • 0M+

        Customers

      • 0+

        Years of Excellence

      • 0+

        R&D Engineers

      • 0+

        Countries

      • 0+

        PARTNERS

      • 0+

        Awards Received