Search
  • For Individuals
      « Back
    • Windows Data Recovery

      Recovers lost or deleted Office documents, emails, presentations & multimedia files.

      Free Standard Professional Premium

    • Mac Data Recovery

      Recovers deleted files, photos, videos etc. on Mac.

      Free Standard Professional Premium

    • Photo Recovery

      Recover photos, videos, & audio files from all cameras and storage on Windows.

      Free Standard Professional Premium

    • Video Repair
    • Photo Repair
    • iPhone Data Recovery
  • For Business
      « Back
    • Email Repair & Converter

      Repair for Exchange Converter for EDB Converter for OST Converter for NSF Converter for OST MBOX Repair for Outlook

    • Database & File Repair

      Repair for MS SQL Repair for Access Repair for QuickBooks Software Repair for Excel Extractor for Windows Backup Repair for MySQL

    • Data Recovery & Erasure

      Data Recovery Professional Data Recovery Technician Mac Recovery for Technician Virtual Machine Recovery File Erasure Software Mobile Erasure Drive Erasure File Eraser Software File Eraser Software for Mac

    • Toolkit

      Exchange Toolkit Outlook Toolkit File Repair Toolkit MS SQL Toolkit Data Recovery Toolkit

    • Forensic

      Email Forensic Exchange Auditor Log Analyzer for MySQL Log Analyzer for MS SQL

  • Store
  • Partners
  • Services
  • Offers
  • Support

 

  • For Individuals
    DIY software for anyone who works with data.

    Windows Data Recovery Recovers lost or deleted Office documents, emails, presentations & multimedia files

    Free Standard Professional Premium

    Mac Data Recovery Especially for Mac users to recover deleted documents and multimedia files from macOS

    Free Standard Professional Premium

    Video Repair Windows Mac Repair multiple corrupt videos in one go. Supports MP4, MOV & other formats.

    StandardPremium

    Photo Recovery Windows Mac Recover photos, videos, & audio files from all cameras and storage on Windows.

    Standard Professional Premium

    iPhone Data Recovery Windows Mac Recover deleted photos, videos, contacts, messages etc. directly from iPhone & iPad

    Recover Erase Toolkit

    Photo Repair Windows Mac Repair multiple corrupt photos in one go. Supports JPEG & other formats.

    Standard Professional Premium


  • For Business
    • Email Repair
    • Email Converter
    • File Repair
    • Data Recovery & Erasure
    • Toolkit
    • Forensic

    Exchange Repair Repair corrupt EDB file & export mailboxes to Live Exchange or Office 365

    Outlook PST Repair Repair corrupt PST & recover all mailbox items including deleted emails & contacts

    OLM Repair Repair Outlook for Mac (OLM) 2011 & 2016 backup files & recover all mailbox items

    Exchange Toolkit Repair EDB & Exchange backup file to restore mailboxes, convert OST to PST, & convert EDB to PST

    Active Directory Repair Repair corrupt Active Directory database (Ntds.dit file) & extract all objects in original form

    EDB to PST Convert online & offline EDB file & extract all mailbox items including Public Folders in PST

    OST to PST Convert inaccessible OST file & extract all mailbox items including deleted emails in PST

    NSF to PST Convert IBM Notes NSF file & export all mailbox items including emails & attachments to PST

    MBOX to PST Convert MBOX file of Thunderbird, Entourage & other clients, & export mailbox data to PST

    OLM to PST Convert Outlook for Mac Data File (OLM) & export all mailbox data to PST in original form

    GroupWise to PST Convert GroupWise mail & export all mailbox items - emails, attachments, etc. - to PST

    EML to PST Convert Windows Live Mail (EML) file & export mailbox data - emails, attachments, etc. - to PST

    Office 365 to PST Connect to Office 365 account & export mailbox data to PST and various other formats

    DBX to PST Convert Outlook Express (DBX) file & export all mailbox data - emails, attachments, etc. - to PST

    SQL Repair Repair corrupt .mdf & .ndf files and recover all database components in original form

    Access Repair Repair corrupt .ACCDB and .MDB files & recover all records & objects in a new database

    QuickBooks Repair Repair corrupt QuickBooks® data file & recover all file components in original form

    MySQL Repair Repair MyISAM & InnoDB tables and recover all objects - keys, views, tables, triggers, etc.

    Excel Repair Repair corrupt Excel (.XLS & .XLSX) files and recover tables, charts, chart sheet, etc.

    BKF Repair Repair corrupt backup (BKF, ZIP, VHDX and .FD) files and restore complete data

    Database Converter Interconvert MS SQL, MySQL, SQLite, and SQL Anywhere database files

    PowerPoint Repair Repair corrupt PPT files and restore tables, header, footer, & charts, etc. like new

    File Repair Toolkit Repair corrupt Excel, PowerPoint, Word & PDF files & restore data to original form

    Data Recovery Windows Mac Recover lost or deleted data from HDD, SSD, external USB drive, RAID & more.

    Technician Toolkit

    Tape Data Recovery Retrives data from all types and capacities of tape drives including LTO 1, LTO 2, LTO 3, & others.

    Virtual Machine Recovery Recover documents, multimedia files, and database files from any virtual machine

    File Erasure Permanently wipe files and folders, and erase traces of apps and Internet activity.

    Standard Corporate

    Mobile Erasure Certified and permanent data erasure software for iPhones, iPads, & Android devices

    Drive Erasure Certified and permanent data erasure software for HDD, SSD, & other storage media Windows Mac

    Exchange Toolkit 5-in-1 software toolkit to recover Exchange database, convert EDB to PST, convert OST to PST, restore Exchange backup, and reset Windows Server password.

    Outlook Toolkit Comprehensive software suite to repair PST files, merge PST files, eliminate duplicate emails, compact PST files, and recover lost or forgotten Outlook passwords.

    File Repair Toolkit Powerful file repair utility to fix corrupt Word, PowerPoint, and Excel documents created in Microsoft Office. It also repairs corrupt PDF files and recovers all objects.

    MS SQL Toolkit 5-in-1 software toolkit to repair corrupt SQL database, restore database from corrupt backup, reset database password, analyze SQL logs, & interconvert databases.

    Data Recovery Toolkit Software helps to recovers deleted data from Windows, Mac and Linux storage devices. Also supports recovery from RAIDs & Virtual Drives.

    Email Forensic Advanced email forensic solution for cyber experts to audit, analyze, or investigate emails & gather evidences.

    Exchange Auditor Exchange Server monitoring solution to automate audits, scans and generate reports ìn real-time.

    Log Analyzer for MySQL Analyze forensic details of MySQL server database log files such as Redo, General Query, and Binary Log.

    Log Analyzer for MS SQL Track & analyze MS SQL Server database transactions log files.

    STELLAR EMAIL FORENSIC

    Advanced email forensic tool to analyze and collect the mailbox data of email clients

    Learn More arrow


    All Products

    All Products

    All Products

    All Products

  • Our Partners
  • Lab Services
  • Trending Searches

    Data Recovery

    Photo Recovery

    Video Repair

    iPhone Data Recovery

    File Erasure Software

    Exchange Repair

    OST to PST

    PST Repair

    Raid Recovery

    MS SQL Repair

  • English Deutsch Français Nederlands Italiano Español 日本語 简体中文
  • Support
Database Recovery 7 minute read

How to Rebuild SQL Database with Corrupted or Deleted Log File?

Updated on March 22nd, 2022
Charanjeet Kaur
Written By
Charanjeet Kaur
Kuljeet Singh
Approved By
Kuljeet Singh

Summary: A SQL database log file might be corrupted due to the large size of transaction log files, accidental deletion of data, etc. A corrupt log file may render the database inaccessible or mark it ‘In Recovery’ or ‘Suspect’ mode. This blog discusses the solutions to repair and rebuild a SQL database with a corrupted or deleted log file.

How to Rebuild SQL Database with Corrupted or Deleted Log File?

Contents

  • Overview of the Issue
  • Reasons for Corrupt Transactional Log Files
  • Ways to Rebuild SQL Database With Corrupt or Deleted Log Files
  • To Conclude

Overview of the Issue

Every SQL database comprises of three file types viz. Main or Primary Database files (.mdf), Secondary database files (.ndf) and Transactional Log files (.ldf). While the main database files and secondary files are used to store database objects like tables, views, indexes, etc., the log files (.ldf) store the transactional logs and changes made by every transaction. The SQL server engine reads the complete log files and performs the recovery process when the SQL Server is started. However, if the reading or recovery process fails, the database remains offline, and it is marked ‘Suspect’ or ‘Recovery Pending’ as per the stage at which failure occurred. This article will discuss the probable causes for corrupt log files, and then we will discuss the solutions to rebuild the SQL database.

Reasons for Corrupt Transactional Log Files

The transaction log files are record files of the SQL database and are critical for recovery. Several reasons may render the log files in the SQL database corrupt. These reasons include:

  1. Unexpected termination or forced system shutdown.
  2. Malware or virus attacks on the system, causing file damage or making the database inaccessible.
  3. Increased size of log files resulting in lack of free space and exceeded configured maximum file size.
  4. Configuration issues with the I/O subsystem used to host the system and user database files.
  5. Changes in the SQL Server Account.
  6. Accidental data deletion.

Ways to Rebuild SQL Database With Corrupt or Deleted Log Files

Before we start with any method, it is important to check the SQL Server error logs and events logs and if you come across an error caused due to hardware issues, you need to get it repaired and see if the problem is resolved. If there is no hardware issue, start with the methods below:

Method 1 – Recover Database from an Existing Backup

To recover a database from an existing backup follow the steps described below:

Step 1: Launch the ‘SQL Server Management Studio’ (SSMS).

open ssms

Step 2: Right-click on the Databases and select ‘Restore Database’.

restore database

Step 3: In the ‘Source’ section on ‘General’ page, specify the source and location.

Step 4: Select the database to be restored from the drop-down list.

Note: If you can’t find your intended database, it means the backup for it has not been created, and the current method can’t be used to repair your database.

Step 5: Click the […] button to open the ‘Select Backup Devices’ box and choose the ‘Backup Media Type’ from the drop-down list.

choose backup media type

Step 6: Click ‘Add’ to open a dialogue box describing what you can select to restore.

add backup file

Step 7: Once you are done with selecting the options in ‘Backup Media’ list, click ‘OK’ to return to the ‘General’ page.

Step 8: Select the database name you want to restore from the list box.

Step 9: Leave the ‘Restore to’ option set at ‘To the last backup taken’ or select a backup of your choice from the ‘Timeline’ and click ‘OK’.

database restore options

Step 10: Select the backups to restore from the ‘Backup Sets to Restore’ grid and click ‘OK’.

Method 2 – Rebuild Damaged or Corrupted Transaction Log file

To rebuild a corrupt or damaged SQL Server log file, you need to put the database in Emergency mode. First, make sure that your data has backup and follow the steps below:

Step 1: Use the below command to set your database in ‘Emergency Mode’.

USE master
GO
ALTER DATABASE [Database_name] SET EMERGENCY
GO
ALTER DATABASE [Database_name] SET SINGLE_USER
GO

Step 2: Now that the database is set to Single User mode, execute the DBCC CHECKDB command with REPAIR_ALLOW_DATA_LOSS option.

DBCC CHECKDB ([DATABASE_NAME], REPAIR_ALLOW_DATA_LOSS) WITH NO_INFOMSGS, ALL ERRORMSGS;
GO

Caution! It is important to know that you might lose data while executing the DBCC CHECKDB command with REPAIR_ALLOW_DATA_LOSS option.

Note: If the corruption still exists, use the following query to rebuild the log file. Before running this query, put the database to Offline Mode and change the name of the corrupt log file.

ALTER DATABASE [original_log_file_name] REBUILD LOG ON (NAME= logicalname, FILENAME=’C:\Program Files\Microsoft SQL Server\MSSQLn.MSSQLSERVER\MSSQL\DATA\file_name.ldf’)

If this method seems a bit difficult and you wish to adopt an easier and effective method then follow the next method.

Method 3 – Repair the SQL Database Using Stellar Repair for MS SQL

Use a SQL Repair tool like The Stellar Repair for MS SQL to restore the database without any complexities. The software uses advanced algorithms to repair corrupt MDF and NDF files. Once repaired, a new transaction log file (.ldf) is created. Follow the steps below to repair and rebuild your SQL log file:

Step 1: Download the Stellar Repair for MS SQL.

Step 2: Once download is complete, run the software. This opens a ‘Select Database’ window with options to browse or find the corrupt MDF file.

options to select corrupt mdf file

Step 3: Once you have located the file click the ‘Repair’ tab at the bottom right corner of the window to start the repairing process.

Step 4: A preview of the repaired database and its components get displayed.

preview of repaired sql databaae components

Step 5: After verifying the data, click ‘Save’.

save option in Stellar Repair for MS SQL

Step 6: To proceed with the repaired database saving process, choose any of these options:

  • New Database – This option saves the data in a new database with ‘Recovered’ prefixed to the database name.
  • Live Database – This option saves the repaired database in an existing database.
  • Other Formats – Using this option, you can save the repaired data in file formats like CSV, HTML, or XLS.
repaired database saving options

Step 7: Enter details to connect to your SQL Server instance, select the location to save the repaired file, then click ‘Next‘.

connect to sql server

Step 8: Choose any of these saving modes:

  • Fast Saving – Use this mode for saving a large-sized repaired database. This option saves the data first and indexes later for faster database restore.
  • Standard Saving – If you need to save the data and indexes together, select the ‘Standard Saving’ mode.

Step 9: Once the database is saved, ‘File saved successfully’ message appears.

To Conclude

It is pertinent to highlight that there are very scarce methods to repair SQL Server database repair. Furthermore, even those available methods may be quite hectic to follow. Therefore, it is easier and more convenient to follow the next option and repair your SQL database using Stellar Repair for MS SQL. It provides a simplified yet effective user interface and recovers all database components such as schemas, triggers, tables, keys, etc., with utmost accuracy. Moreover, once you have your main data files and secondary data files repaired, you will have access to the corrupt or deleted transaction log files (.ldf) as well.

FAQs

Q. How do I restore a .mdf file only?

A. You can restore .mdf files without restoring the .ldf files by using either the SQL Server Management Studio or T-SQL. Try to attach the .mdf files using the SSMS and once the .mdf file is attached successfully the SQL server will create a .ldf file. 

Q. How to check database corruption in SQL Server?

A. You need to run the DBCC CHECKDB command that will verify your database file. It will present the location of problematic areas and suggest the data repair requirements. For infected pages, run the DBCC PAGE command.

Q. Transaction log for database is full, what does it mean?

A. Factors that may cause filling of transaction log for the database include a long-running transaction or a paused database mirroring session. Refer to the Microsoft Troubleshooting Guide to troubleshoot the issue.

Q. Can we shrink the MSDB log file?

A. Yes. Although this is not a frequently used operation for any database. Generally, you can resolve the issue of very large MSDB log files by running the clean-up history task. If it does not work, then check what is using the space and then shrink the MSDB log file using the command below

— SHRINK THE MSDB LOG FILE

USE MSDB
GO
DBCC SHRINKFILE(MSDBLog, 512)
GO

— SHRINK THE MSDB Data File

USE MSDB
GO
DBCC SHRINKFILE(MSDBData, 1024)
GO

Rebuild the indexes once you are done shrinking the MSDB log files.

Q. What is the size limit of the SQL database log file?

The SQL Log file initial size of a newly created database is 8MB, with the auto-growth amount set at 64MB by default. It must be understood that there is no single optimal value for Log File initial size and auto-growth that fits all circumstances. But, as per the best practices, setting the initial size of the SQL Database Log file to 20-30% of the database data file size and the auto-growth to a suitable amount, ranging more than 1024MB, is good for a normal workload.

About The Author

Charanjeet

Charanjeet is a Technical Content Writer at Stellar®who specializes in writing about databases, e-mail recovery, and e-mail migration solutions. She loves researching and developing content that helps database administrators, organizations and novices to fix multiple problems related to MS SQL and MySQL databases and Microsoft Exchange.

Best Selling Products

Stellar Repair for MS SQL

Stellar Repair for MS SQL is an enterpri

Read More

Stellar Toolkit for MS SQL

3-in-1 software package, recommended by

Read More

Stellar Converter for Database

Stellar Converter for Database is an eff

Read More

Stellar Repair for Access

Powerful tool, widely trusted by users &

Read More

Leave a comment Cancel reply

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

44  +    =  52

Table of Contents    

  1. Overview of the Issue
  2. Reasons for Corrupt Transactional Log Files
  3. Ways to Rebuild SQL Database With Corrupt or Deleted Log Files
  4. To Conclude

Categories

Related Posts

Database Recovery

How to Fix Error “The database cannot be recovered because the log was not restored”?

Stellar Author Charanjeet Kaur April 15, 2022 Read More
Database Recovery

How to Fix System Database Corruption in SQL Server?

Stellar Author Charanjeet Kaur April 8, 2022 Read More
Database Recovery

How to Get Data from a Corrupt SQL Table?

Stellar Author Charanjeet Kaur March 4, 2022 Read More

Stellar Official Website

Stellar Data Recovery Inc.
48 Bridge Street Metuchen,
New Jersey 08840,
United States

ALSO AVAILABLE AT

About

  • About us
  • Career
  • ISMS Policy
  • Privacy Policy
  • Terms of Use
  • License Policy
  • Refund Policy
  • End User License Agreement

RESOURCES

  • Blog
  • Articles
  • Product Videos
  • Knowledge Base
  • Case Studies
  • Whitepapers
  • Software Catalog

NEWS & EVENTS

  • News
  • Events

PARTNERS

  • Affiliates
  • Resellers
  • Distributors

Useful Links

  • Contact Us
  • Support
  • Special Offers
  • Student Discounts
  • Awards & Reviews
  • Downloads
  • Store
  • Sitemap
Follow Us

Stellar & Stellar Data Recovery are Registered Trademarks of Stellar Information Technology Pvt. Ltd. © Copyright 2022 Stellar Information Technology Pvt. Ltd. All Trademarks Acknowledged.

DMCA.com Protection Status
We use cookies on this website. By using this site, you agree that we may store and access cookies on your device Read More Got it!