Section: Create reusable views

Create a view

sql
sql
CREATE VIEW recent_posts AS
SELECT p.id, p.title, u.email AS author_email, p.created_at
FROM posts p
JOIN users u ON u.id = p.user_id
WHERE p.created_at >= date('now', '-30 day');
Explanation

Views are great for simplifying repeated report queries or exposing app-friendly shapes.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Create reusable views
Query a view
Read from the named projection like a table.
OpenIn sheetsqlsame section
Create an AFTER INSERT trigger
Write to an audit log when a row is created.
OpenIn sheetsql1 tag match
Touch updated_at from a trigger
Maintain a timestamp on row changes.
OpenIn sheetsql1 tag match
Normalize data with a generated column
Compute a lowercased email for indexing or search.
OpenIn sheetsql1 tag match
Index a generated column
Speed up queries over a derived value.
OpenIn sheetsql1 tag match