Replacing, stacking and dropping views
To change a view, replace it:
CREATE OR REPLACE VIEW completed_orders AS
SELECT * FROM orders
WHERE status = 'Completed' AND order_date >= '2024-01-01'To remove one, DROP VIEW completed_orders. Dropping a view never deletes data; the tables
underneath are untouched.
Views can build on views. A customer_revenue view can feed a top_customers view, which can feed
a dashboard. Keep the chain short, and name views for what they mean (active_customers), not how
they work (customers_join_orders_2).
Views and speed: a plain view is just its query, run fresh every time. If it's slow, the view is slow too. Some databases also have materialised views, which store the results and need refreshing (PostgreSQL, Oracle; SQL Server calls them indexed views). DuckDB doesn't have them: use
CREATE TABLE … AS SELECTfor a snapshot instead.