SQL Server LDF Recovery in 5 Ways
SQL Server LDF recovery depends on one fact, which is whether the database closed cleanly before the log file disappeared. Microsoft states that SQL Server rebuilds a missing log only after a clean shutdown.
Five ways follow, from the safest to the last resort. Copy the MDF and NDF files to another volume before you try any of them.
Quick SummarySQL Server LDF recovery depends on a clean shutdown of the database. Search for the original LDF file before you rebuild anything. Restore a backup under a new name when a verified chain exists. Attach the MDF file with ATTACH_REBUILD_LOG after a clean shutdown. Use emergency mode repair after an unclean shutdown as the last manual option. Use SQL Recovery when the attach fails or the MDF file is damaged.
What Happens When the LDF File Disappears?
The LDF file stores the transaction log. SQL Server needs the log at startup to finish or undo the transactions that were open when the database closed.
The database stays unavailable without the log. Microsoft describes the RECOVERY PENDING state as a database that is not damaged but cannot start because files are missing. The SUSPECT state means recovery failed and further action is needed.
A clean shutdown means that no users and no open transactions existed when the database closed. SQL Server rebuilds a log safely only in that case.
Do You Know?Microsoft states that an attach uses the old log file whenever the file sits in the old location, whether or not the database closed cleanly. Search the old path and the old volume before you rebuild.
How to Check the Database State Before You Start?
Query sys.databases for the state and sys.master_files for the log file path.
SELECT name, state_desc
FROM sys.databases
WHERE name = N'SalesDB';
SELECT name, physical_name, type_desc, state_desc
FROM sys.master_files
WHERE database_id = DB_ID(N'SalesDB');
You know the shutdown was clean when you stopped the service yourself or detached the database before the file went missing. A crash, a power loss or a killed service means the shutdown was not clean.
Copy the MDF and NDF files before every method below. Microsoft requires physical copies of the files before a repair.
Which Way Fits Your Log File Case?
Match your case to the table.
| Your case | Start with |
|---|---|
| You have the original LDF file or a copy of it | Method 1 |
| Full and log backups exist and you accept the loss after the last log backup | Method 2 |
| The database closed cleanly and the MDF and NDF files are healthy | Method 3 |
| The database closed unexpectedly and no backup exists | Method 4 |
| The attach fails or the MDF file is damaged | Method 5 |
How to Recover a SQL Database Without the LDF File?
Every example uses the database SalesDB. Replace the names and the paths with your own values.
Method 1: Find the Original LDF File and Attach With It
Use this method when the file exists anywhere. Search the Recycle Bin, the previous versions of the folder, the volume backup and the quarantine of your antivirus software.
CREATE DATABASE SalesDB
ON (FILENAME = N'D:\Data\SalesDB.mdf'),
(FILENAME = N'D:\Data\SalesDB_Data2.ndf'),
(FILENAME = N'E:\Log\SalesDB_log.ldf')
FOR ATTACH;
Microsoft advises that you retain every detached log file until the database attaches without them. Follow SQL Server error 1813 when the attach fails with that message.
Method 2: Restore From Backup Under a New Name
Use this method when a full backup and log backups exist. A lost log file rules out a tail of the log backup so the restore ends at the last log backup.
RESTORE DATABASE SalesDB_Restored
FROM DISK = N'D:\Backup\SalesDB_full.bak'
WITH MOVE N'SalesDB' TO N'E:\Data\SalesDB_Restored.mdf',
MOVE N'SalesDB_log' TO N'F:\Log\SalesDB_Restored.ldf',
NORECOVERY;
RESTORE LOG SalesDB_Restored
FROM DISK = N'D:\Backup\SalesDB_log1.trn'
WITH RECOVERY;
Restore the differential backup and every log backup in order before the final statement. A restore over the original name makes SQL Server ask for a tail of the log backup and returns error 3159. The new name leaves the damaged files in place for Methods 3 to 5.
Method 3: Attach the MDF File With ATTACH_REBUILD_LOG
Use this method after a clean shutdown when all MDF and NDF files are healthy. Microsoft documents the option for READ_WRITE databases and the option needs every data file.
Detach the entry when SQL Server still lists the database in the RECOVERY PENDING state. Copy the MDF and NDF files before you detach.
EXEC sp_detach_db @dbname = N'SalesDB';
CREATE DATABASE SalesDB
ON (FILENAME = N'D:\Data\SalesDB.mdf'),
(FILENAME = N'D:\Data\SalesDB_Data2.ndf')
FOR ATTACH_REBUILD_LOG;
SQL Server creates a new log file of 1 MB in the default log location. Find the logical name and resize the file.
SELECT name, physical_name
FROM sys.master_files
WHERE database_id = DB_ID(N'SalesDB') AND type_desc = N'LOG';
ALTER DATABASE SalesDB
MODIFY FILE (NAME = N'SalesDB_log', SIZE = 1024MB, FILEGROWTH = 256MB);
BACKUP DATABASE SalesDB
TO DISK = N'D:\Backup\SalesDB_after_rebuild.bak';
Microsoft states that the rebuild breaks the log backup chain and recommends the full backup in the last statement. Follow SQL Server attach database access denied error when the attach fails on permissions.
Method 4: Rebuild the Log in Emergency Mode
Use this method after an unclean shutdown when no backup exists. Microsoft calls the repair an emergency last resort and requires physical copies of all database files before it starts.
ALTER DATABASE SalesDB SET EMERGENCY;
ALTER DATABASE SalesDB SET SINGLE_USER WITH ROLLBACK IMMEDIATE;
DBCC CHECKDB (N'SalesDB', REPAIR_ALLOW_DATA_LOSS) WITH ALL_ERRORMSGS, NO_INFOMSGS;
ALTER DATABASE SalesDB SET MULTI_USER;
DBCC CHECKCONSTRAINTS WITH ALL_CONSTRAINTS;
Microsoft states that a successful repair leaves the database physically consistent and sets it ONLINE. The repair can produce transactional inconsistencies and no full ACID guarantee. Microsoft advises DBCC CHECKCONSTRAINTS and an immediate backup. The log keeps its default size until you resize it.
Heads UpReferential integrity can be inaccurate after the repair because the repair does not check foreign keys. Validate the business data by hand before the application starts. DBCC CHECKDB REPAIR_ALLOW_DATA_LOSS does not work lists the cases where the repair fails.
Method 5: Recover the Data With SQL Recovery
Use this method when the attach fails, when the emergency repair fails or when the MDF file is damaged. Recover a SQL database from suspect mode lists the manual options that come before it.
SQL Recovery opens the MDF and NDF files without SQL Server and works on a copy so your original file remains untouched. SQL Recovery previews tables, views, triggers, rules, functions and stored procedures and exports them to a SQL Server database, SQL scripts or CSV files.
Download SQL Recovery Buy SQL Recovery
- Install SQL Recovery and select Add File.

- Browse to the MDF file and select Advanced Scan. Confirm the SQL Server version and tick the deleted records option.

- Open the preview and check the recovered database components.

- Select Export and save the objects to a SQL Server database, to SQL scripts or to CSV files.

What Does SQL Recovery Need on Your System?
Check both tables before you install SQL Recovery on the server or on a separate workstation.
Software Specifications
| Attribute | Detail |
|---|---|
| Software name | SQL Recovery |
| Version | 14.0 |
| File types | MDF and NDF |
| SQL Server versions | 2025, 2022, 2019, 2017, 2016, 2014, 2012, 2008 R2, 2008, 2005 and 2000 |
| Scan modes | Quick Scan and Advanced Scan |
| Export options | SQL Server database, SQL scripts and CSV |
| SQL Server installation | Needed only for export to a live server |
| Demo limit | Preview of every item and export of 25 records per table and 5 other objects |
System Specifications
| Component | Requirement |
|---|---|
| Processor | Intel Core 2 Duo E4600 at 2.40 GHz or equivalent |
| RAM | 4 GB |
| Hard disk space | 100 MB free |
| Operating system | Windows 7, 8 and 10 (32 or 64 bit), Windows 11 (64 bit), Windows Server 2008, 2012 R2, 2016, 2019, 2022 and 2025 |
| Framework | Microsoft .NET Framework 4.5 or later |
| Permission | Launch SQL Recovery as administrator |
Common Questions on LDF Recovery
Can You Attach an MDF File Without the LDF File?
Yes under two conditions. Microsoft states that the database must be READ_WRITE and must have closed cleanly with no open transactions. FOR ATTACH rebuilds a single missing log and ATTACH_REBUILD_LOG rebuilds one or more missing logs.
Does ATTACH_REBUILD_LOG Lose Data?
Microsoft names no data loss for the rebuild. Microsoft states that the rebuild breaks the log backup chain and recommends a full backup right after the attach.
Can You Use ATTACH_REBUILD_LOG on a READ_ONLY Database?
No. Microsoft limits the option to READ_WRITE databases. A READ_ONLY database needs its log files at the location stored in the primary file.
What Does REPAIR_ALLOW_DATA_LOSS Do to the Log File?
Emergency mode repair rebuilds the log when recovery fails. Microsoft states that the rebuild can lose transactional consistency and leaves no full ACID guarantee. The log keeps its default size until you resize it.
Why Does the Rebuilt Log File Have a Size of 1 MB?
ATTACH_REBUILD_LOG creates a new log file of 1 MB in the default log location. Resize the file with ALTER DATABASE MODIFY FILE before the workload starts.
Can SQL Recovery Open an MDF File Without the LDF File?
Yes. SQL Recovery opens the MDF file and the NDF files without SQL Server and without a log file. The software previews the objects and exports them to a SQL Server database, SQL scripts or CSV files.
How to Avoid Losing the Log File Next Time?
Place the log file on its own volume with free space and schedule log backups on every database in the full recovery model. SQL Server error 9001 shows what the engine reports when the log becomes unavailable.
Copy the MDF and NDF files before every maintenance task that stops the service.
Who, How and WhyAndrew Jackson, Technical Content Specialist, wrote this guide. The attach rules, the clean shutdown condition, the 1 MB log and the log backup chain warning follow the Microsoft CREATE DATABASE page and the Microsoft page on detach and attach. The emergency mode repair rules follow the Microsoft DBCC CHECKDB page. The database states follow the Microsoft page on database states. The T-SQL was checked for syntax against Microsoft documentation and was not executed on a live server. The detach step for a database in the RECOVERY PENDING state comes from general practice and not from a Microsoft page. The SQL Recovery steps and tables follow the screens and the product page of the software. The guide did not test an attach or a repair on a live server. The guide exists because a missing log file needs a different fix after a clean shutdown than after a crash.
Key Takeaways
- SQL Server LDF recovery starts with one question, which is whether the shutdown was clean.
- FOR ATTACH_REBUILD_LOG needs a clean shutdown and every MDF and NDF file.
- The rebuilt log has a size of 1 MB and breaks the log backup chain.
- Take a full backup right after a log rebuild and resize the new log file.
- Emergency mode repair is the last manual option and leaves no full ACID guarantee.
- SQL Recovery opens the MDF file without the LDF file when the attach fails.