CREATE VIEW
CREATE VIEW stores a SELECT definition under a table-like name. Querying an ordinary view evaluates that definition against the current source data; the view does not store or refresh result rows.
Syntax
text
CREATE [TEMP | TEMPORARY] VIEW [IF NOT EXISTS] name
[(column, ...)]
AS SELECT ...An optional column list names the view's result columns. A view is read-only unless an INSTEAD OF trigger handles the requested write. Materialized views are not supported.
Examples
Naming a filtered query
sql
CREATE TABLE items(id INTEGER PRIMARY KEY, active Bool);
INSERT INTO items VALUES (1, true), (2, false);
CREATE VIEW active_items AS
SELECT id FROM items WHERE active;sql
SELECT *
FROM active_items
ORDER BY id
FORMAT csv;text
1Reading changed source data
The view reflects a later update without a refresh command:
sql
UPDATE items SET active = true WHERE id = 2;sql
SELECT *
FROM active_items
ORDER BY id
FORMAT csv;text
1
2Use DROP VIEW to remove the definition. See CREATE TABLE AS SELECT when a separate stored copy of a query result is required.