SQL Server Log Explorer
Restore Data

How to Recover a Missing or Corrupt NDF File in SQL Server

Andrew Jackson Modified: 8 Minutes Reading
On this page

Quick Answer

SQL Server NDF file recovery depends on where the file sits. Your database remains online when a secondary NDF file is gone. Only that filegroup goes offline. You get 3 ways to fix it. Restore the file from a backup with a tail log backup. Set the file offline and work around it. Scan the file with recovery software when no backup exists. Offline NDF files return only through a restore. Copy all database files before you act.

NDF files are the secondary data files of a SQL Server database. Losing one does not always stop your database. Losing the MDF file does.

This guide shows what remains online, which tables fail and which of the 3 fixes fits your backups. Our tests ran on a real database with an extra filegroup and the results sit next to the methods.

What Happens When an NDF File Goes Missing?

Microsoft tracks the state of every file apart from the state of the database. Your file location decides what you lose.

Where the file lives Database state What works What fails
Primary filegroup (MDF file) Not online Nothing until you restore Every query
Secondary filegroup (NDF file) Online Tables in the other filegroups Tables with a heap or an index in the offline filegroup

Microsoft states a filegroup is available only when all of its files are online. Microsoft states the optimizer avoids nonclustered indexes in an offline filegroup so some SELECT statements still work. SELECT fails when the offline filegroup stores the heap or the clustered index of the table.

INSERT, UPDATE and DELETE fail on any table that has an index in the offline filegroup.

What did Our Test Show?

We built a database with 2 filegroups. Emp sat on PRIMARY and Hist sat on a second filegroup with its own NDF file.

Statement Result on our copy
sys.database_files The NDF file showed OFFLINE and the database showed ONLINE
SELECT from Emp Worked and returned both rows
INSERT into Emp Worked
SELECT from Hist Msg 8653 because the table resides in a filegroup that is not online
INSERT into Hist Msg 8653
ALTER DATABASE MODIFY FILE with ONLINE Msg 155 because ONLINE is not a recognized option

Msg 8653 is a compile error. TRY and CATCH in the same batch does not catch it and the batch stops before earlier SELECT statements return rows. Send every statement in its own batch when you test a copy.

Which Recovery Path Fits Your Backups?

What you have What it means What to do
FULL recovery model, a full backup and log backups Microsoft documents a file restore with no data loss Use Method #2
SIMPLE recovery model Microsoft documents a file restore only for secondary filegroups marked READ_ONLY Restore the full database or use Method #3
No backup An offline file cannot return without a restore Use Method #1 to save the other filegroups, then use Method #3 for the lost data
The MDF file is damaged The database is not online Use Method #3 or restore the full database

Our recovery models and backup types guide explains how the recovery model limits your options.

How do You Check the State of Your NDF Files?

Query the file states before you act. Microsoft names the states ONLINE, OFFLINE, RESTORING, RECOVERY PENDING, SUSPECT and DEFUNCT.

SELECT name, type_desc, state_desc FROM sys.database_files;
SELECT name, state_desc FROM sys.databases WHERE name = N'YourDB';

Our test executed both statements. They listed the MDF file, the LDF file and the NDF file with a state for all 3.

System and Software Specifications for NDF Recovery

System Specifications

Component Requirement
Server permission sysadmin role for ALTER DATABASE and RESTORE. We executed every test as sysadmin
Disk space Free space for the full backup, the tail log backup and a copy of the surviving files
Backups A full backup that includes the NDF file and every log backup after it
PC for the recovery software Windows up to Windows 10 with 512 MB of RAM and 50 MB of free disk space

Software Specifications

Item Requirement
Offline file restore Microsoft states all editions of SQL Server support it. We tested on SQL Server 2022 (RTM CU26) Express on Linux
Online file restore Microsoft limits it to editions with online restore support. Check the edition page of your version
Recovery software Lists SQL Server 2019 and earlier

How do You Recover an NDF File in SQL Server?

Method #1: Set the File Offline and Work Around It (Free, Filegroup Unavailable)

Use this method to bring the rest of your database online while you plan the restore. Microsoft states a corrupt file can go offline and return only through a restore from backup.

ALTER DATABASE [YourDB] MODIFY FILE (NAME = N'YourNdfLogicalName', OFFLINE);

Our test executed this statement on a copy. Our database stayed ONLINE and only the filegroup of that file went offline. Tables in the other filegroups worked as the table above shows.

Find the logical name of the file in the name column of sys.database_files.

Method #2: Restore the NDF File With a Tail Log Backup (Free, No Data Loss)

Use this method with the FULL recovery model. Your restore sequence has 3 statements and the first one is easy to get wrong.

BACKUP LOG [YourDB] TO DISK = N'D:\Backups\YourDB_tail.trn' WITH NORECOVERY;
RESTORE DATABASE [YourDB] FILE = N'YourNdfLogicalName'
FROM DISK = N'D:\Backups\YourDB_full.bak' WITH NORECOVERY;
RESTORE LOG [YourDB] FROM DISK = N'D:\Backups\YourDB_tail.trn' WITH RECOVERY;

Microsoft states you must always take tail log backups before an offline file restore. Our test proved why the NORECOVERY option matters.

  • Plain log backup. Our file restore failed with Msg 3159 because the tail of the log was not backed up. RESTORE LOG failed next with Msg 3117.
  • Log backup with NORECOVERY. Our database moved to RESTORING and the 3 statements finished without errors. All 3 files showed ONLINE.
  • Result. Hist returned its 2 original rows. Emp also returned the row we added while the file was offline.

Our error 3159 guide explains the tail log message and our tail log backup guide shows the backup options.

Heads Up

Our test used a small copy and a fresh backup chain. Your chain can have many log backups and every one must restore in order with NORECOVERY before the last one.

Method #3: Scan the Files With SQL Recovery Utility (Paid, No Backup Needed)

Use this method when no backup exists. SQL Recovery Utility opens the MDF or NDF file without a live SQL Server. The software shows a preview of all database items and exports to a live SQL Server database, a SQL script or CSV files.

  • Click Open and select the damaged .mdf or .ndf file.
  • Select Quick Scan or Advanced Scan and tick Auto detect SQL version.
  • Check the preview of the recovered items.
  • Select SQL Server Database, enter the login details and select a new or an existing database.
  • Select With only schema or With schema and data and click Export.

Open button of the recovery software for a damaged database file
Quick Scan and Advanced Scan options of the recovery software
Preview of recovered database objects in the recovery software

SQL Recovery Utility

Scan a damaged MDF or NDF file and export the recovered data.

Heads Up

Scan copies of the files and work on the copies only.

How do You Protect a Multi Filegroup Database?

  • Take a backup of every filegroup. Full database backups include all files. Our test restored the NDF file from that backup.
  • Take log backups in FULL recovery. File restores need them to roll the file forward.
  • Test the restore on a copy. Use WITH MOVE for every file and check the row counts.
  • Store the NDF file on reliable disks. Lost volumes take the filegroup offline.

FAQs

Does a Missing NDF File Take the Database Offline?

No. Microsoft states a missing secondary file affects only its filegroup. Files of the primary filegroup take the database offline.

Can You Set an NDF File Back Online Without a Restore?

No. Microsoft states an offline corrupt file returns only through a restore from backup. Our ALTER DATABASE statement with ONLINE returned Msg 155.

What does Error 8653 Mean for an NDF File?

Error 8653 means the query processor cannot build a plan because the table resides in a filegroup that is not online. Restore the file to clear it.

Do You Need a Tail Log Backup for an NDF File Restore?

Yes for an offline file restore. Microsoft states you must always take it first. Take it with NORECOVERY or the restore fails with Msg 3159.

Can You Recover an NDF File Without a Backup?

Yes, with a scan of the file. Method #3 reads the file contents without a live SQL Server and exports the items it finds.

Which Tables Fail When an NDF File is Offline?

Tables with a heap or a clustered index in that filegroup fail on SELECT. Any table with an index in that filegroup fails on INSERT, UPDATE and DELETE.

About this guide

We checked this guide against Microsoft documentation on 30 Nov 2026 for SQL Server 2019, 2022 and 2025. We executed every statement of Methods #1 and #2 on a restored copy on our test server.

Microsoft documents the states on its file states page and the restore sequence on its file restores page.