Deleted data in SQL Server can often be restored, but the method depends entirely on what happened after the delete and how the database is configured. The direct answer is that SQL Server itself has no "undelete" command; recovery comes from one of four sources: a recent backup, the transaction log (if the database uses the full recovery model), a previously captured copy such as a snapshot or replicated/secondary database, or—when none of those exist—from the physical data pages using third-party tools or careful manual forensics. Which of these applies determines whether recovery is routine, difficult, or impossible.
The single most important distinction is between a DELETE statement and a TRUNCATE TABLE. A DELETE removes rows one at a time, logs each row removal, and can be rolled back if the transaction is still open or recovered from the log afterward. TRUNCATE TABLE deallocates whole pages, is minimally logged, and is effectively unrecoverable from the log for the removed rows—only a backup or a page-level tool can help. A DROP TABLE is similar: the table's data pages are deallocated, and restoring the table definition plus its data usually requires a backup or specialized recovery software.
First, stop writing to the database
Before anything else, the practical rule is to stop activity on the affected database. Every new transaction can cause the log to be reused (in simple recovery) or, in the worst case, cause SQL Server to overwrite the very pages that still hold the deleted rows. If the deletion was recent and the database is in full recovery mode, the log still contains the delete operation, and log backups preserve it. But if the log has been truncated by a log backup cycle and no backup captured that period, the information is gone the moment those log records are reused.
So the first steps are: take a transaction log backup immediately (if the database is in full or bulk-logged recovery and the log has not been truncated), avoid restarting services unnecessarily, and resist the urge to run DBCC CHECKDB with repair options—repair can destroy recoverable data. If the database is in simple recovery mode, the log is truncated at every checkpoint, so log-based recovery is usually not available unless a log backup was taken while the records still existed.
Option 1: Restore from backup
This is the cleanest and most reliable path. If you have a full backup taken before the deletion, restore it to a different database name (never overwrite the live database), then copy the missing rows back into the production table. The advantage is that it exercises no guesswork. The limitation is that the backup reflects a point in time; any changes made after the backup are lost unless you also have log backups.
With full recovery and a chain of log backups, you can restore the full backup, then restore log backups with STOPAT to a point just before the delete:
The STOPAT time should be a moment before the accidental DELETE. This point-in-time restore is the standard professional answer, and it is exactly why full recovery with regular log backups matters: it turns an accidental delete from a disaster into a short restore exercise.
Option 2: Read the transaction log
If no backup covers the deletion but the database is in full recovery mode and the log records still exist (not yet truncated by a log backup that was then deleted, and not reused), you can sometimes reconstruct the deleted rows from the log. SQL Server does not expose the log as a queryable table, so this requires either undocumented functions or third-party log-reading tools.
The common approaches are:
fn_dblog and fn_dump_dblog: undocumented system functions that return the contents of the current or a backed-up transaction log. They can be used to find LOP_DELETE_ROWS operations and, with considerable effort, reconstruct the deleted row values from the log records. This is advanced work—the output is in internal formats that must be decoded—and Microsoft does not document or guarantee it. Third-party log readers such as ApexSQL Log, Red Gate SQL Log Rescue (historically), or similar tools that parse the log and present deleted rows in a readable form. These are often the practical choice for DBAs without deep log-format expertise.
A key point: log-based recovery only works if the relevant log records still exist. Once a log backup has been taken and the log truncated, or once a checkpoint in simple recovery has truncated the log, that information is unavailable through this route. Many people search for "how can deleted data be restored in SQL Server" expecting a simple command; the honest answer is that the log is not a queryable archive, and recovery from it is a forensic process rather than a one-line operation.
Option 3: Database snapshots, replication, and secondary copies
If the database has a database snapshot (SQL Server Enterprise and Developer editions) created before the delete, you can query the snapshot to read the old row values and insert them back into production. Snapshots are sparse files that preserve the pre-modification state of pages, so a snapshot taken before the deletion will still show the deleted rows.
Similarly, if the database participates in replication, log shipping, or Always On availability groups with a readable secondary, the secondary may still contain the deleted rows until it receives and applies the delete. In an availability group with a readable secondary, you can query the secondary (if it has not yet applied the change) and copy the rows back. Log shipping secondaries can be read in standby mode (if the restore hasn't occurred), and replication subscribers may have older data depending on latency.
These options are often overlooked and can be the fastest path when they exist, because they require no restore and no log forensics.
Option 4: Physical page recovery with third-party tools
When no backup, no usable log, and no snapshot exist, the last resort is recovering the data from the physical pages. When rows are deleted, SQL Server marks the space as free but often does not immediately overwrite the bytes. Third-party recovery tools (for example, Stellar, EaseUS, or dedicated SQL recovery utilities) can scan the MDF file for deleted row remnants and extract them. Success depends on whether the pages have been overwritten by subsequent activity, so this works best on a copy of the database file taken immediately after the deletion—and it should be attempted on a copy, never the original, to avoid making things worse.
Manual page forensics using DBCC PAGE is possible in principle but is not a realistic recovery strategy for most organizations: deleted rows are not guaranteed to remain coherent, and the effort is substantial. Third-party tools automate this at a cost and with no guarantee.
What never works, and what people get wrong
Several common assumptions lead people astray:
There is no built-in "undelete" statement. SQL Server has no RESTORE ROW or equivalent. Recovery is always via backup, log, snapshot, or forensic tooling. Rolling back requires an open transaction. If the DELETE was executed inside a transaction that is still open (for example, in an uncommitted batch you haven't yet committed or rolled back), you can simply ROLLBACK. Once committed, that route is closed. Some careful practitioners run destructive statements inside an explicit transaction and verify row counts before committing, precisely to preserve this option. Simple recovery mode means no log-based recovery. With simple recovery, the log is truncated at checkpoints, so there is no retained history of the delete for log-based restoration. Backups and snapshots are the realistic options there. TRUNCATE and DROP behave differently. These deallocate pages and are minimally logged, so restoring the removed rows usually means restoring the table from a backup or using page-level recovery tools—not reading the log. Restoring directly over production is risky. Restore to a separate database, verify the data, then copy rows back. Overwriting production with an old backup can compound the loss.
How to make future deletions recoverable
The best answer to "how can deleted data be restored" is prevention: configure the database so that recovery is a routine operation. Specifically:
1: Use the full recovery model for databases where point-in-time recovery matters, and take regular transaction log backups. This preserves the log records needed for STOPAT restores and gives you a recovery window. 2: Test restores regularly. A backup that has never been restored is an assumption, not a guarantee. 3: Consider database snapshots for high-value databases if your edition supports them, or maintain a readable secondary. 4: Restrict and audit destructive permissions. Many accidental deletes come from ad hoc DELETE statements run without a WHERE clause; limiting who can run them and requiring transactions reduces the blast radius. 5: Use a staging pattern for large deletes: select the rows you intend to delete into a holding table or confirm counts inside a transaction before committing.
A practical decision path
When a deletion has just happened, work through this order:
| Situation | Best recovery route |
|---|---|
| Delete is in an uncommitted transaction | ROLLBACK |
| Full recovery, recent full + log backups | Restore with STOPAT to a separate database, copy rows back |
| Database snapshot exists from before the delete | Query the snapshot, reinsert rows |
| Readable secondary / replication subscriber has older data | Copy rows from secondary |
| Full recovery, log not yet truncated, no backup | Log reading via fn_dblog or a third-party log tool |
| No backup, no log, no snapshot | Third-party page-level recovery on a copy of the MDF; no guarantee |
The honest summary is that SQL Server does not restore deleted data by itself; it gives you the mechanisms—backups, transaction logs, snapshots, secondaries—and the outcome depends on whether those mechanisms were in place and whether the relevant log or pages still exist. The earlier in that chain you act, and the less you write to the database afterward, the better the chances.