Module: 14 — Views Previous: 05 — Business Reporting Views · Next: 07 — View Performance
information_schema queries to run before modifying a base tableViews are powerful, but they are not tables, not stored procedures, and not a general-purpose abstraction layer. This file exists specifically because these limitations are where production incidents and interview trick questions both concentrate.
Every engineer eventually reaches for a View to solve a problem it isn’t designed for — a parameterized report, an indexable derived dataset, a way to enforce a constraint. Knowing the boundary in advance prevents both wasted engineering time and production breakage.
An analyst tries to build vw_orders_by_date_range intending to pass a date range at query time the way a stored procedure parameter would work. Views don’t support parameters — the correct pattern is a View with WHERE applied at the calling query, or a stored procedure/function instead. A team that doesn’t know this loses a sprint discovering it the hard way.
SELECT * — sometimes across a dozen dependent Views discovered only when dashboards start erroring.-- This does NOT work — Views cannot accept parameters:
-- CREATE VIEW vw_orders_by_range(p_start DATE, p_end DATE) AS ... ❌ invalid syntax
-- Correct pattern: filter the View at query time
SELECT * FROM vw_completed_order_revenue
WHERE region = 'APAC'; -- filtering happens outside the View definition
CREATE VIEW view_name AS
SELECT ... FROM t
ORDER BY col -- allowed, but ignored unless the View has no
-- outer ORDER BY, and is not merged into a larger query
LIMIT 10; -- allowed inside a View, but rarely useful — LIMIT
-- applies to the View's own result set, not filtered
-- input, unless paired carefully with subqueries
CAN a View do this?
✅ Filter/aggregate/join base tables
✅ Expose a subset of columns
✅ Be queried like a table
✅ Be nested inside other Views
❌ Accept parameters like a function/procedure
❌ Be directly indexed (only base tables can be indexed)
❌ Enforce constraints (NOT NULL, UNIQUE) beyond what the base table already enforces
❌ Guarantee performance improvement over its underlying query
❌ Survive a base-table column rename/drop without breaking (if referenced)
information_schema.VIEWS for any View definition text referencing that table/column.CASCADE dependency tracking for Views in MySQL the way foreign keys have ON DELETE CASCADE — you must search definition text yourself.SELECT TABLE_NAME, VIEW_DEFINITION
FROM information_schema.VIEWS
WHERE TABLE_SCHEMA = DATABASE()
AND VIEW_DEFINITION LIKE '%annual_salary%';
MySQL does track View-to-table dependency for the purpose of blocking a DROP TABLE in some configurations, but it does not block a column-level ALTER TABLE ... DROP COLUMN or RENAME COLUMN even when Views depend on that exact column — the failure surfaces later, at View query time, not at ALTER TABLE time. This asymmetry is the single most common source of “the report broke in production but the migration passed CI” incidents in teams that lean heavily on Views.
Maintain a lightweight internal registry (even a simple query against information_schema.VIEWS, run in CI before any migration touching a table with dependent Views) — treat View dependency auditing as a required migration-review step, the same way foreign key impact is reviewed.
A View never improves query performance versus running the equivalent SQL directly — a common misconception. Any performance difference comes from how the View is written (e.g., an analyst using a well-optimized View instead of writing a naive ad hoc join), not from the View mechanism itself.
ORDER BY inside a View definition is honored only when the View is queried without further transformation that would reorder results (e.g., an outer JOIN or UNION) — don’t rely on a View’s internal ORDER BY for guaranteed output order in a complex consuming query.SELECT * inside a View — this alone prevents the most common breakage mode.information_schema.VIEWS before every schema migration.| Mistake | Consequence |
|---|---|
Assuming DROP TABLE protection extends to ALTER TABLE ... DROP COLUMN |
Silent View breakage at query time |
| Trying to parameterize a View | Invalid syntax; wasted engineering time |
| Expecting a View to be indexable | Not possible; must index the base table |
ALTER TABLE step.Views are not parameterizable, not directly indexable, and do not natively track column-level dependency the way foreign keys do. Understanding these boundaries prevents both wasted design effort and unplanned production breakage.
information_schema query you’d run before renaming sales_order_items.unit_price, and list every View in this module it would find.