CREATE OR REPLACE VIEW is a Data Definition Language (DDL) command that either generates a new logical view or rewrites the definition of an existing view in a single, transactionally safe step. If the view already exists, the database engine replaces its stored SELECT statement while preserving permissions and dependent objects (such as grants or other views) when possible. This avoids the need to issue a separate DROP VIEW followed by CREATE VIEW, reducing downtime and dependency breakage. The new definition must be compatible with any objects that depend on the view, otherwise the statement fails. Some dialects allow the optional RECURSIVE keyword or WITH CHECK OPTION constraints, but availability varies.
view_name
(identifier) - Name of the view to create or replacecolumn_list
(identifiers) - Optional explicit column names if you want to rename or reorder columns in the viewSELECT statement
(query) - The query that defines the view's virtual tableWITH CHECK OPTION
(keyword) - Enforces that inserts/updates via the view satisfy the view predicate (dialect specific)CASCADE
(keyword) - Propagates CHECK OPTION to underlying views (some dialects)CREATE VIEW, ALTER VIEW, DROP VIEW, MATERIALIZED VIEW, WITH CHECK OPTION, GRANT
PostgreSQL 7.3 (2002)
No. It only rewrites the view metadata and does not lock source tables for reads or writes beyond the brief metadata update.
Yes, as long as dependent objects do not rely on the old column list. If they do, the statement fails until those dependencies are updated.
You cannot. Use ALTER VIEW RENAME TO or DROP VIEW followed by CREATE VIEW with the new name.
No. INCLUDE it only when you want to enforce that DML through the view satisfies the view's WHERE clause.