You can restore a dropped view in SQL by recreating it from a saved definition, since most database engines don't provide an "undelete" command for views. The fastest path is to retrieve the original CREATE VIEW statement from source control, a DDL audit log, a backup, or a schema-comparison tool, then run it again. If none of those exist, you'll reconstruct the query from documentation or surrounding code. The key condition: act before anything overwrites the relevant logs or backup retention window, and confirm you're reconnecting to the same database, schema, and dependency chain the original view used.
This guide walks through the ordered steps, the engine-specific quirks (SQL Server, PostgreSQL, MySQL, Oracle), the failure modes that trip people up, and how to prevent the next drop from becoming a crisis.
Why a dropped view can't be "undeleted" like a row
A view is a stored query, not the data it exposes. When you run DROP VIEW, the database removes the metadata definition and its permissions; the underlying tables are untouched. There's no transaction log entry that replays the view's text automatically, and even engines with point-in-time recovery restore the whole database to a moment, not a single object.
That distinction matters for your recovery plan. You're not recovering data; you're recovering a text definition plus its ownership, grants, and dependencies. The data was never lost, so a full database restore is usually overkill and often riskier than recreating the view.
One nuance: some engines log DDL statements in a way you can parse. SQL Server's default trace and extended events can capture CREATE VIEW statements if configured. PostgreSQL logs DDL only if log_statement is set to ddl or all, and those logs may be rotated. So recovery success depends heavily on what was captured before the drop, which is why the first step below is to stop and check, not to start typing.
Prerequisites: what to confirm before you begin
Before touching anything, gather four facts:
1: The exact name and schema. Views can share a name across schemas. Confirm whether it was dbo.vw_Orders, reporting.vw_Orders, or another schema entirely. 2: The database and environment. Production, staging, or a replica? A view restored to the wrong environment looks fixed but isn't. 3: Dependencies. Which other views, stored procedures, reports, or applications reference it? Dropping a view breaks objects that depend on it, and recreating with a different column list can break them again. 4: Who dropped it and when. The timestamp narrows your search in logs and backups, and the actor tells you whether a DROP or a DROP ... CASCADE (or its equivalent) was used, which affects what else may have vanished.
If you have a change-ticket system, check whether the drop was intentional. Recreating a view that was deliberately removed to fix a performance or security issue can reintroduce the problem. That's a real stop condition: if the drop was part of an approved change, get sign-off before restoring.
Ordered steps to bring the view back
Step 1: Freeze the situation
Stop scheduled jobs, deploy pipelines, or migration scripts that might recreate or further alter objects in that schema. You want a stable target while you recover. Notify anyone who owns downstream reports so they don't "fix" it independently and create conflicting versions.
Check for success: You can confirm no automated process is queued to touch the schema in the next hour.
Step 2: Search version control first
This is the highest-yield, lowest-risk source. Most teams keep schema objects as SQL files or migrations. Search the repository for the view name:
In a migrations folder, look for the file that created it, then replay any later ALTER VIEW migrations in order. In a schema-as-code setup, the current file should be exact. In Git history, git log -S "vw_Orders" finds commits that added or changed it.
Recreate from the latest definition, not the first one. Running an old version silently reintroduces bugs that were fixed later.
Check for success: Compare the recreated column names and types against what dependent objects expect.
Step 3: Mine DDL audit logs
If version control comes up empty, check whether your engine logged the DDL. On SQL Server, look at the default trace or a server audit; on PostgreSQL, check log_statement = 'ddl' output in the server logs; on Oracle, DBA_OBJECTS history and unified auditing may help if enabled. MySQL's general query log captures statements only when it's turned on, which many production servers leave off for performance.
A caution: log retention is often 7–30 days. If the drop happened longer ago than your retention window, this path is closed. Don't spend hours parsing logs that no longer contain the event.
Step 4: Restore from a backup to a scratch database
If logs and source control fail, restore the most recent full backup plus any log or differential backups to a temporary database. Do not restore over production. Then extract the view definition with your engine's metadata function. This is the safest large-scale approach, and it also recovers ownership and permissions if you script them out.
The trade-off: restoring a backup can take significant time and storage on large databases, and it only gets you back to the backup's point in time. Any changes to the view after that backup are lost. That's usually acceptable for a view, since they change rarely, but verify.
Step 5: Recreate and re-grant
Run the recovered CREATE VIEW statement in the correct schema. Then reapply:
GRANT statements for roles and users. Ownership (ALTER AUTHORIZATION on SQL Server, ALTER VIEW ... OWNER TO on PostgreSQL). Any WITH SCHEMABINDING or SECURITY INVOKER/SECURITY DEFINER options the original had.
Check for success: Query the view, and confirm that application users (not just admins) can select from it. Permission errors after recreation are the most common "it's still broken" complaint.
Step 6: Rebuild dependents
If dependent views or procedures were dropped by a cascade, recreate them in dependency order. Query the catalog to find them. A simple validation: run each dependent object once, or check that the catalog reports them as valid.
Step 7: Verify and document
Run a SELECT against the view, compare a few rows to the base tables, and check row counts. If your engine supports it, run a validation function or EXPLAIN to confirm the query plan doesn't error. Then log what happened and why, so the next person doesn't repeat the archaeology.
Engine-specific recovery notes
SQL Server. There's no DROP VIEW undo. Use OBJECT_DEFINITION(OBJECT_ID('dbo.vw_Orders')) before a drop (it returns NULL after), or script objects with SSMS or sqlcmd. After a drop, check the default trace for Object:Deleted events and the CREATE VIEW statement if captured. Restoring a backup to a scratch database and scripting the view is reliable.
PostgreSQL. pg_views and pg_get_viewdef() expose definitions while the view exists. After a drop, they're gone. If log_statement was set to ddl or all, the logs hold the original statement. DROP VIEW ... CASCADE silently removes dependent views, so plan to recreate the whole chain.
MySQL. SHOW CREATE VIEW gives the definition before a drop; after a drop, it doesn't. The general query log or binary log may contain the statement if logging was enabled. Recreate with CREATE OR REPLACE VIEW when iterating, which avoids a destructive drop in the first place.
Oracle. DBA_VIEWS.TEXT holds the query text while the view exists. After a drop, use Flashback Drop for tables, but views generally need recreation from a backup or DBMS_METADATA export taken earlier. Export schemas regularly with DBMS_METADATA.GET_DDL.
A quick reference for what's available after a drop:
| Engine | Definition available after drop? | Best recovery source |
|---|---|---|
| SQL Server | No (unless trace captured it) | Source control, backup, default trace |
| PostgreSQL | No | log_statement logs, backup |
| MySQL | No | General/binary log, backup |
| Oracle | No | DBMS_METADATA export, backup |
Failure modes and how to spot them
Schema drift. You recreate the view but the underlying tables changed since the backup. The CREATE VIEW succeeds, but queries fail or return wrong data. Symptom: column-not-found errors or suspiciously empty results. Check: compare base table columns to the definition's expected columns.
Permission gaps. The view exists but the app can't read it. Symptom: permission denied for specific users. Check: query as a non-admin test account.
Cascading drops. A DROP ... CASCADE (PostgreSQL) or DROP VIEW with dependent objects removed more than you expected. Symptom: other views or procedures are missing too. Check: list objects in the schema and compare to your inventory.
Restoring to the wrong environment. A common and embarrassing error. Confirm connection strings and server names twice.
Reintroducing a removed object. If the view was dropped for security or performance reasons, recreating it can undo that fix. This is the clearest stop condition: consult the change owner before restoring.
Worked example: a realistic recovery
Suppose an analyst drops sales.vw_MonthlyRevenue in PostgreSQL at 10:15 a.m. on a Tuesday. The team has:
A Git repo with the view as of three weeks ago, plus one ALTER VIEW migration from last week that added a region column. log_statement = 'ddl' enabled, with 14-day retention. A nightly backup.
The recovery path: check Git for the latest definition, find the ALTER VIEW migration, apply both in order, then re-grant SELECT to the reporting role. Total time: about 15 minutes. The log check is a cross-reference, not the primary source, which is fine—logs confirm the timestamp and that no other objects were touched.
If Git had been missing, the log_statement logs from 10:15 a.m. would contain the CREATE VIEW text, and the team could copy it. If logs were off, the nightly backup restores to a scratch database, and pg_get_viewdef() scripts the view. Each fallback adds time: logs, minutes; backup restore, 30 minutes to hours depending on size.
Preventing the next drop
The best recovery is the one you never need.
Schema in version control. Keep every view as a migration or schema file. This turns a disaster into a git checkout. Principle of least privilege. Most users don't need DROP VIEW. Restrict it to a small group. Audit DDL. Enable DDL logging and keep retention long enough for your recovery needs. Test restores. A backup you've never restored isn't a backup you can trust. Use CREATE OR REPLACE in engines that support it, so routine changes never require a destructive drop. Script objects before changes. Before any intentional drop, export the definition.
FAQ
Can I undo a DROP VIEW without a backup? Sometimes, if DDL logging captured the statement and logs are still retained. Otherwise no—the definition must come from source control, logs, or a backup.
Do I need to restore the whole database? Usually not. Restore to a scratch database and extract just the view, then recreate it in production. That's faster and safer than replacing production data.
What if the view was dropped by a migration that also changed tables? Recovering the view alone may produce wrong results if the base schema moved. Reconcile the table changes first, then recreate the view against the current schema.
Why can't I see the view after recreating it? Check the schema name and search path. The view may exist in a different schema than expected, or your session's search_path (PostgreSQL) or default schema (SQL Server) may not include it.