You can retrieve erased data from SQL Server only if a copy of it still exists somewhere: a full backup, a transaction log backup, a database snapshot, a page from a piece of forensic tooling, or the transaction log itself when the database is still in full recovery mode and the log hasn’t been truncated. If the DELETE or TRUNCATE happened after the last log backup and someone already truncated or recycled the log, the rows are gone unless a backup, replica, or file-level copy survives. So the first move is not to run a recovery script; it is to stop writing to the database and inventory the copies you actually have.

A few framing points make the rest of this guide easier to follow. Microsoft SQL Server’s DELETE is a logged operation, and in the FULL recovery model those log records stay in the log until a log backup runs; in SIMPLE, the log is reused at checkpoints, so undelete-by-log is usually impossible. TRUNCATE TABLE is also logged per page, not per row, so log-based undelete tools can’t reconstruct individual deleted rows from it the way they can from a DELETE. And DROP TABLE / DROP DATABASE leave their own trail. The steps below assume you want the data back without corrupting the surviving database, and that you are working on SQL Server on-premises or in a VM you control; managed offerings such as Azure SQL Database and Amazon RDS impose their own point-in-time restore features, which are covered where relevant.

Step 1: Freeze the Situation Before You Touch Anything

Prerequisites: an account with server-level or database-level access, plus the discipline to avoid writes to the affected database.

1: Stop application writes to the affected database if you can — pause the app, put the database in RESTRICTED_USER or SINGLE_USER mode, or take the app tier offline. Every insert, update, or checkpoint pushes older log records closer to reuse. 2: Record the exact time window of the erasure, the account that did it, the table name, and the approximate row count. Log recovery (and forensic tools) work best with a narrow time range. 3: Take a copy of the database files and the current transaction log if the server can be paused. A file-level copy of the .mdf and .ldf (with the database detached or the server stopped) preserves the log at its current state for later analysis. 4: If you have a full backup from before the incident, verify it with RESTORE VERIFYONLY and note its log sequence number (LSN) chain. 5: Do not run shrink operations, index rebuilds, or DBCC SHRINKFILE on the database; each can force log truncation and erase the evidence you need.

Success check: you can state, with dates, the last good full backup, the last log backup, and whether the database is in FULL or SIMPLE recovery. If you can’t answer those three questions yet, keep going before attempting any restore.

Stop condition: if this is a production system with regulatory retention obligations and no tested backups, stop here and involve a database administrator and your data-protection or compliance contact before running any recovery tool against the live files.

Step 2: Establish the Recovery Model and the Log’s Fate

The recovery model tells you what’s possible. Query it with SELECT name, recovery_model_desc FROM sys.databases WHERE name = 'YourDB'; and confirm the log reuse state with DBCC SQLPERF(LOGSPACE) and sys.dm_db_log_stats.

SIMPLE: log records are reused at checkpoint. Unless a log backup or snapshot captured the DELETE before the checkpoint, step 3 loses most of its value; go to backup-based recovery. FULL: log grows until a log backup runs. If no log backup happened since the DELETE, the records remain in the live log, but be aware that many other logged operations have since been written — recovery works if the relevant LSNs are still in the active log. BULK_LOGGED: bulk operations are minimally logged, DELETE behavior is similar to FULL for row deletes, but truncated-table recovery is limited.

Checkpoint the facts in one place: last full backup, last differential backup, last log backup, and current time. Compare to the incident time. A backup after the incident is only useful if it captured data before it; a log backup after the incident is exactly what you want.

Step 3: Try Log-Based Undelete (FULL Recovery Model, Live or Copied Files)

The mechanism: SQL Server writes each DELETE as a set of log records containing the deleted row image. Third-party log readers parse the active log or a detached copy and emit INSERT statements to put the rows back. This works for DELETE and, with caveats about page-level logging, for some TRUNCATE scenarios only when accompanied by a copy of the original data pages; it cannot resurrect rows after log truncation.

1: Determine the log’s usable window from the earliest LSN in sys.dm_db_log_info. If that window begins after your incident time, stop — the records are gone. 2: Copy the database files (and log) to a scratch server or directory. Never let a log-reading tool write to the original. 3: Attach a copy or point the tool at the detached files, target the incident window, and preview the reconstructed rows in a scratch table. 4: Compare counts and key columns against the expected data. If they match, script out INSERTs and deploy them into the live table or an archive table first. 5: Reconcile foreign keys, triggers, and identity columns; identity seeds will not be restored automatically, so use SET IDENTITY_INSERT where necessary.

Success check: the recovered row count matches the pre-delete count (or a sample you can verify), and spot-checked values match the deleted rows.

Stop condition: if the tool reports the log window is shorter than the incident, or if this database is under a compliance audit, don’t improvise — back up everything and get a data-recovery specialist engaged before proceeding.

Genuine warning: log-based undelete tools are effective but not magic. They read page structure and can fail on encrypted databases, on databases that are offline, or where the incident predates the earliest log record. Test any tool on a copy of the database, not the original.

Step 4: Restore from Backups — The Most Reliable Path

If you have a pre-incident backup chain, restore beats undelete. The mechanics differ by recovery model.

Prerequisites: the pre-incident full backup, any differential backups, and every log backup in between, plus free space at least the size of the backup set.

1: Take a tail-log backup of the live database if it’s still online and no data changes after the incident matter for recovery. Use WITH NORECOVERY so the database stays in restoring state. 2: Restore the last pre-incident full backup with NORECOVERY on a scratch instance or a copy, then the differentials with NORECOVERY, then log backups in LSN order up to the incident time. 3: When you get to the final log backup, use WITH STOPAT = '' to stop just before the DELETE. Or use a log restore with STOPBEFOREMARK on a named mark if you established one. Use RESTORE ... WITH STANDBY if you need to inspect data before finalizing. 4: Query the restored copy to confirm the rows are back. Extract them with SELECT INTO or INSERT ... SELECT into a staging table on the live database. 5: Bring the live database out of recovery with RESTORE WITH RECOVERY only when you’re satisfied you don’t need more log restores.

Success check: the restored database contains the rows, and the extracted data can be re-inserted into production without duplicates. Use a staging table plus a NOT EXISTS anti-join keyed on the original primary key.

A worked example makes the timing concrete. Suppose a 200 GB database in FULL recovery has a full backup at 20:00 Sunday and log backups every 15 minutes. A DELETE runs Monday at 09:07. The 09:00 log backup is already safely in the backup chain, so you restore the full, then apply log backups up to the 09:00 one, then stop; the restored copy holds the database as of 09:00, three minutes before the incident. You finish by copying the deleted rows to production. In an illustrative arithmetic sense, that’s roughly two log backups after 08:45 that matter — everything earlier is safely stored. If instead the DELETE ran at 09:06 and the log backup ran at 09:10 (after the incident), that last log backup contains the DELETE log records but only the point-in-time stop lets you avoid the actual deletion. A STOPAT of 09:06:30 ignores it; a STOPAT of 09:12 replays it.

The common failure: attempting to restore with sporty point-in-time times that fall outside the recovered log chain. The error message will be “The STOPAT option is not valid because the specified point in time is not covered by the log sequence.” That usually means you restored a log whose LSN range sits outside the window; inspect the LSNs from RESTORE HEADERONLY on each backup and reorder them.

Step 5: Use Snapshots, Database Mirroring, and Availability Groups

Database snapshots, taken before the incident, are read-only point-in-time views you can query directly and copy from. The SNAPSHOT must still exist; SQL Server snapshots are subject to source database writes on the original volume, and if the source grows, snapshots can be dropped by the server to stay healthy. Query the snapshot for the deleted rows (it contains page data as of snapshot time) and copy into production.

For Always On availability groups, the secondary replicas lag the primary by the redo queue. If a secondary replica is not too far behind, you can query it, or you can fail over and then restore. Mirroring setups provide a full save of the mirrored database at the point of break; breaking the mirror lets you access the mirror database directly. Both are conditional wins: the copy must predate the incident, and failover planning should stay clear of the primary.

Step 6: Recover TRUNCATE TABLE and DROP TABLE Cases

TRUNCATE TABLE is logged page by page and cannot be inverted by row-level log readers on SQL Server versions that log truncation as deallocation. Recovery relies on backup/restore, a database snapshot, or a third-party recovery tool that can rebuild from the allocation map. DROP TABLE is trickier: the object metadata is gone, and the allocation pages are deallocated; backup-based restore of the object into a scratch database, using the LSN window, is the reliable method. If you know the table’s data pages are still on disk in a detached file, specialized forensic tools can sometimes recover them — but this requires stopping writes and file-level analysis, and should be treated as a last resort with a professional involved.

One common confusion: TRUNCATE is fast because it deallocates pages rather than logging individual row deletes. That’s also why no log reader can holistically reconstruct every row. Backups, snapshots, and availability-group copies exist precisely to fill that gap.

Step 7: Know When the Data Is Actually Gone

The hard truth about SQL Server log recovery: if the relevant log records are overwritten, truncated by a checkpoint in SIMPLE recovery, or removed by a log backup that has since been deleted, no local trick retrieves the data. The active log holds what hasn’t been overwritten, and the backup chain holds what it captured; there is no shadow copy in SQL Server itself. If every copy is gone, the rows are unrecoverable from SQL data files, and the realistic path is a data-recovery or forensic service that analyzes physical files — with a professional involved and no guarantee of recovery.

There are also edge cases where “erased” isn’t what it seems:

Deletes that never committed. A suddenly missing table may be a transaction still open on another connection, leaving rows invisible to your session. Check sys.dm_tran_active_transactions and BLOCKING chains before assuming loss. Accidental updates. Rows replaced by an UPDATE are a different recovery pattern from DELETE; log readers can produce an “before” image from update log records, but only within the log window. Truncated backups plus shrunk log files. If someone issued a SHUTDOWN WITH NOWAIT or forced shrink, the log’s recoverability window can collapse in minutes. Log backups on a separate drive. A chain is only as good as its latest link; the classic failure is a full backup without its accompanying log backups, which can’t pass the incident.

Step 8: Verify, Then Reinsert Safely

Once the deleted rows are staged, treat the reinsert as a controlled migration rather than a quick INSERT.

1: Land the recovered rows in a staging table with the same schema. 2: Reconcile duplicates with a NOT EXISTS anti-join or CHECKSUM-based comparison against the surviving table. 3: Reinsert in batches inside explicit transactions so a failure doesn’t leave a half-restored state. 4: Repair indexes, triggers, foreign keys, and identity seeds; identity values on reinserted rows won’t match the original unless you use SET IDENTITY_INSERT. 5: Confirm downstream consumers — reporting, replication, audit tables — see the right data.

Success check: counts and key checksums match, and the application’s own queries return the expected totals.

Stop condition: if the recovered rows are on a regulated production system and the deletion triggered a legal hold or audit, the reinsertion should be reviewed by whoever owns the compliance process rather than executed unilaterally.

Choosing Between the Paths

The right recovery path is a matter of what survived, not preference. A comparison on equivalent criteria — recoverability window, required preconditions, downtime, and side effects — makes the choice clearer.

Path Recoverability window Requires Downtime Trade-offs
Log-based undelete Until log records are overwritten (FULL model) Live or copied log, compatible tool Minimal Fails after log truncation; page-level limits
Point-in-time restore Full backup plus every log backup Intact backup chain and space Some, if restoring a scratch instance Restores whole database copy; reinsert needed
Database snapshot Snapshot’s lifespan Snapshot exists and is healthy Low Snapshot fragility; source writes consume space
Availability group secondary Redo queue depth Healthy secondary Low (query secondary) Copy may lag; failover risk
Forensics/file-level Until physical overwrite Detached copies, expert service High Cost, no guarantee

On-premises SQL Server gives you the full menu. Azure SQL Database and Azure SQL Managed Instance offer automated backups with point-in-time restore (typically a 7–35 day window depending on tier and configuration, and long-term retention if configured) and no access to the physical log, so the log-based route is generally unavailable there. Amazon RDS for SQL Server offers automated backups and point-in-time restore over a configurable retention window. In both managed contexts, the practical answer is usually “restore to a point in time into a new database, copy the rows out,” and restores go through the platform’s tooling rather than RESTORE DATABASE.

Preventing the Next Erasure

Recovery is a response; the better question is how to make the next incident boring. In FULL recovery model, take frequent log backups so the recovery window is short and the log stays recoverable. Test restores regularly — a backup you haven’t restored is a hypothesis. Consider database snapshots for high-value reporting tables, and ensure DELETE permissions are tightly scoped. A soft-delete column plus a scheduled purge job is often cheaper than recovery: the data is never really erased until the purge runs, and the purge preserves a window for reconciliation. Monitoring tools that alert on large DELETEs per unit time also catch the mistake before the log cycles.

Finally: when someone asks you to recover erased rows, the answer is a race against the log’s reuse. Freeze writes, inventory copies, and only then choose between undelete, restore, and snapshot. The rare cases where every copy is gone should be treated as data-forensics problems, not database tweaks — and the best recovery you’ll ever execute is a tested backup chain you never needed until today.