Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Database schemas evolve continuously. As business requirements change, tables gain or lose columns, business definitions shift, and views must be modified or retired.
In MySQL, managing views involves altering existing definitions using ALTER VIEW or CREATE OR REPLACE VIEW, inspecting view metadata, and safely removing obsolete views with DROP VIEW.
MySQL supports two synonymous statements to modify an existing view:
Note: If view_name does not exist, ALTER VIEW throws an error.
Note: If view_name exists, it is replaced; if it does not exist, it is created cleanly. For this reason, CREATE OR REPLACE VIEW is preferred in idempotent deployment scripts.
To permanently delete one or more views:
A view is dependent on the underlying columns referenced in its SELECT clause. Consider what happens when base tables change:
If an administrator drops a column used by the view:
The view definition is not deleted, but querying it immediately yields:
To resolve this, the view must be recreated with the updated schema.
When creating or altering views, MySQL allows specifying the internal evaluation algorithm:
| Algorithm | How it Works | Best For / Limitations |
|---|---|---|
| MERGE | The view's text is merged directly into the outer query before optimization. Filters in WHERE are pushed down. | Highly efficient, updatable views. Cannot be used with GROUP BY, DISTINCT, or aggregates. |
| TEMPTABLE | The view is materialized into a temporary table in memory/disk first; the outer query scans that temp table. | Required when views use GROUP BY, HAVING, or window functions. Not updatable. |
| UNDEFINED (Default) | MySQL automatically selects MERGE if possible, falling back to TEMPTABLE. | Recommended for general use. |
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Updatable Views & WITH CHECK OPTION | Security & Data Abstraction with Views |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.