CREATE VIEW
statement followed by the view name and the query that defines the view.
For example, assuming you have two tables employees
and departments
(we created them in the tables section of this guide),
you can create a view that combines data from both tables:
SELECT
statement, and also modify the underlying logic behind the columns as long as the name and type remain the same.
Because the view does not contain any data itself, replacing it is a fast, atomic and idempotent (repeatable) operation.
Because the limitations prevent you from making any breaking changes, the operation is safe to perform online (while the application is running).
For example, if you want to include the employee email in the employee_details
view, you can replace the view as follows:
DROP VIEW
statement followed by the view name:
CREATE OR REPLACE VIEW
syntax.
You can do this in a single transaction to ensure that the view is always available for querying, but be aware that if you remove columns
that are still in use, you may break the application.