What is a VIEW in SQL?
Answer
A VIEW is a named, stored SQL query that appears as a virtual table — it has no physical data of its own but presents data from one or more underlying tables. Think of it as a saved query with a name. Creating a view: CREATE VIEW active_users AS SELECT id, name, email FROM users WHERE status = "active";. Query it like a table: SELECT * FROM active_users WHERE name LIKE "John%";. Benefits: (1) Simplify complex queries: hide JOINs and filters behind a simple name; (2) Security: expose only specific columns/rows to users, hiding sensitive data (e.g., expose user names but not passwords); (3) Abstraction: decouple application code from table structure — rename tables without changing application queries; (4) Reusability: define once, use in many queries. Limitations: views are generally not faster than the underlying query (MySQL executes the view's SELECT each time — no query result caching). Updatable views: simple views (single table, no DISTINCT/GROUP BY/aggregates) can have INSERT/UPDATE/DELETE. MySQL supports materialized views indirectly via scheduled refresh to a real table.
Previous
What is the difference between a clustered and non-clustered index?
Next
What is a stored procedure in MySQL?