A VIEW is an object that saves a query’s text in the database catalog and exposes the result set as if it were a table. Whenever you select from the view, the database re-executes the underlying query and returns the latest data (unless the view is materialized or cached by the engine). Views can simplify complex joins, encapsulate business logic, enforce row-level security, and provide limited column visibility. They do not store data themselves, consume almost no disk space, and automatically reflect changes in the base tables. Views can be updatable if the query meets certain rules (single base table, no aggregations, etc.), and you can add WITH CHECK OPTION to restrict writes that violate the view definition. Some dialects support additional clauses such as RECURSIVE, OR REPLACE, SECURITY DEFINER, and MATERIALIZED. Dropping a view removes only the definition, not the underlying data. Use views to build reusable, versioned, and governed query layers on top of raw tables.
view_name
(identifier) - Name of the view to create.column_list
(identifier list) - Optional explicit column names for the view.SELECT ...
(query) - Any valid SELECT statement whose result defines the view.OR REPLACE
(keyword) - Overwrites an existing view.TEMP
(TEMPORARY) - keyword|||View lives only in the current session.WITH CHECK OPTION
(keyword) - Prevents writes that would make rows invisible through the view.CASCADED
(keyword) - Applies CHECK OPTION to underlying views as well.CREATE VIEW, MATERIALIZED VIEW, WITH CHECK OPTION, ALTER VIEW, DROP VIEW, TABLES, SELECT
ANSI SQL-86
Ordinary views do not store data. They keep only the query definition. Each time you query the view, the database executes the underlying SELECT to return current results. Materialized views differ because they cache data on disk.
You can update, insert, or delete rows through a view if it is updatable. The main requirements are that the view references a single base table and avoids constructs like GROUP BY, DISTINCT, UNION, or window functions. Use WITH CHECK OPTION to enforce that modified rows still satisfy the view’s filter.
A view neither inherently speeds up nor slows down queries. The optimizer expands the view into its underlying query, so execution time matches running that query directly. Performance problems usually stem from missing indexes or chains of nested views, not the view object itself.
A standard view is virtual and always reflects current base table data. A materialized view physically stores the result set, enabling faster reads but requiring manual or automatic refreshes to stay up to date.