The process of recovering deleted data from a SQL database depends first on what kind of "deleted" occurred—a DELETE that has not yet been committed, a committed DELETE still covered by a transaction log or backup, a DROP/TRUNCATE, or physical corruption—because each leaves different traces and requires different recovery moves; in most production systems the reliable path is restore-and-replay from backups and transaction logs, while log scraping, page inspection, and third-party tools are fallback techniques whose success depends on the engine, configuration, and how much time has passed. The question does not name a database engine (SQL Server, PostgreSQL, MySQL, Oracle, SQLite, and others behave very differently), a recovery scenario, or a version, so this answer describes the general principles and the engine-specific differences that matter most; the concrete commands below are illustrative for common systems, and exact syntax and feature availability must be checked against the documentation for the specific version in use.
Clarify what "deleted" means before doing anything
The single most useful step is to stop writing to the affected database and to classify the deletion. There are four broad situations, and they are not interchangeable:
Uncommitted deletion: a transaction ran DELETE but has not committed. The rows are still recoverable in the same session or by rolling back. Committed deletion with log or backup coverage: the deletion committed, but the database is in full recovery mode with transaction-log backups, point-in-time restore capability, or a recent backup. This is the normal, reliable recovery case. Committed deletion without coverage: the deletion committed and no backup or log preserves it—typical of simple recovery mode, or of databases where logs are truncated. Recovery then depends on residual pages, free-space reuse, or forensic tooling, and success is uncertain. Structural deletion: TRUNCATE TABLE, DROP TABLE, or DROP DATABASE. These remove or deallocate data at a different level, and ordinary row-level recovery does not apply.
Each situation has a different answer. Conflating them is the most common source of failed recoveries and of further damage.
The first, safe steps
Before touching anything, preserve the current state. Take a file-system or volume snapshot of the database files and, if the database is still running, a copy of the current transaction log. Recovery attempts—especially log reads and page inspection—can alter or overwrite the evidence they depend on. Work on a copy or a restored environment, not the live production instance, whenever possible.
Then answer these questions: What engine and version? What recovery model or logging configuration? When was the last full backup and the last log backup? Is the deletion still in an open transaction? Has the database been written to since? These determine which of the paths below is viable.
Rollback and uncommitted deletes
If the transaction is still open, the simplest recovery is to roll it back:
In SQL Server, an open transaction in another session can sometimes be identified and rolled back explicitly, but doing so from a second session is a deliberate, disruptive act. In PostgreSQL, a transaction that has not committed can be rolled back the same way. In MySQL with InnoDB, ROLLBACK works while the transaction is open. Once the transaction has committed, rollback is no longer available and you must move to the log- or backup-based methods. This is the distinction that matters most: commit is the dividing line. Before commit, recovery is ordinary transaction control; after commit, recovery is backup-and-log work or forensics.
Restore from backup and replay the log
For committed deletions with backup coverage, the standard and most dependable method is point-in-time recovery. The idea: restore the most recent full backup, then apply transaction-log (or WAL, or binlog) records up to just before the destructive statement, so the database state reflects the moment before the delete. The exact procedure is engine-specific.
In SQL Server, a database in the full recovery model records every change in the transaction log until a log backup is taken. You restore the full backup WITH NORECOVERY, restore subsequent log backups WITH NORECOVERY, and stop at the point in time before the delete, using STOPAT:
The restored copy can then be queried to extract the lost rows and reinsert them into production. This is the safest pattern: recover to a side database, verify, then copy rows back. Do not restore over production until you are certain.
In PostgreSQL, the equivalent is point-in-time recovery using a base backup plus archived WAL segments, configured with recovery_target_time or recovery_target_lsn in postgresql.conf (or recovery.signal and related settings depending on version). Recovery to a target before the delete yields a database state without the deleted rows, from which you can extract and reinsert them. PostgreSQL does not offer a built-in "undo this one statement" command; the log-based replay is the mechanism.
In MySQL with InnoDB, binary logs (binlog) record changes when enabled. You can restore a backup and replay the binary log to a point before the delete using mysqlbinlog with stop-datetime or stop-position, typically into a separate instance. The binlog format (statement, row, or mixed) affects what can be replayed and how precisely you can target the moment. Row-based logging generally replays more predictably.
In Oracle, the analogous mechanism is RMAN backup plus archived redo logs with point-in-time recovery (RECOVER DATABASE UNTIL TIME ...), and Flashback Query/Flashback Table can recover recent row changes if undo retention allows—a distinctly Oracle feature worth knowing about.
The recurring principle: backup plus log replay to a target time or log sequence number, performed on a copy, then selective reinsertion. This works because the log records the change; it is not a guess.
When there is no backup or log: log scraping and page inspection
If logs are unavailable or truncated, recovery becomes forensic. Several techniques exist, each with real limits:
Transaction-log reading tools. Third-party utilities read the transaction log or WAL directly and extract records of deleted rows, reconstructing INSERT statements. On SQL Server, tools in this class (for example, log-reading products) can parse the log if it has not been truncated or overwritten. Their success depends on log retention and on the log not having been recycled. These are commercial tools; results vary and should be validated on a copy. Free-space and page inspection. Deleted rows may remain physically present in data pages until overwritten. On SQL Server, DBCC PAGE can inspect pages, and sys.dm_db_page_info provides page metadata; recovering rows this way requires understanding the storage format and is painstaking. On PostgreSQL, pageinspect and related extensions expose page contents, but dead tuples are cleaned by VACUUM and the free space map reuses space, so timing matters enormously. DELETE versus TRUNCATE/DROP. DELETE removes rows and, depending on engine, may leave recoverable traces in the log and in pages. TRUNCATE deallocates pages and is minimally logged in many engines, which usually makes log-based row recovery far harder or impossible. DROP TABLE removes the object; recovery typically requires restoring the object from backup or, in some engines, a "deleted object" catalog (for example, SQL Server's sys.objects history is not a recovery mechanism—restore is). Do not assume a technique that works for DELETE will work for TRUNCATE.
A general caution: page-level or log-level recovery is where most misleading claims circulate. Tools and techniques exist, but "recover any deleted row" is not a guarantee. Treat it as best-effort, validate on a copy, and preserve evidence before trying.
The special case of TRUNCATE and DROP
These deserve separate mention because they change the recovery calculus. TRUNCATE is a data-definition-like operation in many engines: it deallocates the table's pages and is often minimally logged, so transaction-log scraping has little or nothing to read. Recovery usually means restoring from backup. DROP TABLE removes the table definition and data; some engines retain metadata and allow recovery within a narrow window (for example, Oracle's recycle bin, if enabled, allows FLASHBACK TABLE ... TO BEFORE DROP), but SQL Server and PostgreSQL do not have a general "undelete dropped table" command—restore is the mechanism. If a DROP occurred, the first question is whether a backup exists; the second is whether an engine-specific recycle-bin feature applies.
What to do after recovery
Once rows are recovered into a side database or a staging table, verify them against known expectations (row counts, key ranges, checksums) before reinserting into production. Reinsertion should be selective and audited. Then address the causes: confirm the backup and log-backup schedule actually produces restorable backups (test restores regularly, not just backups), confirm the recovery model matches the recovery objective, and add safeguards such as soft-delete flags, restricted privileges, and review of bulk DELETE/TRUNCATE operations. Recovery is the emergency; prevention is the durable answer.
A compact comparison
| Engine | Primary recovery route | Key dependency | Notable caveat |
|---|---|---|---|
| SQL Server | Restore full + log backups with STOPAT, or log-reading tools | Full recovery model, intact log backups | Simple recovery model truncates log; log scraping limited |
| PostgreSQL | Base backup + WAL replay to recovery_target_time/LSN | Archived WAL | No built-in single-statement undo; VACUUM reclaims dead tuples |
| MySQL (InnoDB) | Restore backup + mysqlbinlog replay to stop position/time | Binary logging enabled, appropriate format | Row vs. statement binlog affects replay fidelity |
| Oracle | RMAN point-in-time recovery; Flashback Query/Table | Archived redo logs; undo retention | Recycle bin helps DROP only if enabled |
| SQLite | Restore from file backup; no server log | File-level backup | No transaction-log replay mechanism comparable to servers |
The table is illustrative of common configurations, not exhaustive; versions and settings change what is available.
FAQ
Can I just run ROLLBACK after a committed delete? No. Once the transaction commits, rollback is no longer available; you need log/backup recovery or forensics.
Does a DELETE always leave recoverable rows in the log? Not reliably. It depends on the engine, recovery model, whether the log has been truncated or recycled, and how much time has passed. Log scraping is best-effort.
Is TRUNCATE recoverable the same way as DELETE? Generally no. TRUNCATE is often minimally logged and deallocates pages, making log-based row recovery much harder; restore from backup is usually required.
Will a third-party tool always recover my data? No. Tools depend on intact logs or unoverwritten pages; success is conditional and should be validated on a copy.
What is the single most important preventive measure? Tested, restorable backups with log backups matching your recovery objectives—regular test restores, not just backup jobs that report success.