SQLite Triggers, Views, and Generated Columns Cheatsheet/Normalize data with a generated column

Compute a lowercased email for indexing or search.

Section: Triggers and generated values

Normalize data with a generated column

sql
sql
CREATE TABLE contacts (
  id INTEGER PRIMARY KEY,
  email TEXT NOT NULL,
  email_normalized TEXT GENERATED ALWAYS AS (lower(email)) STORED
);
Explanation

Generated columns can simplify lookups and enforce repeatable derivations close to the data.

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 Triggers and generated values
Index a generated column
Speed up queries over a derived value.
OpenIn sheetsqlsame section
Create an AFTER INSERT trigger
Write to an audit log when a row is created.
OpenIn sheetsqlsame section
Touch updated_at from a trigger
Maintain a timestamp on row changes.
OpenIn sheetsqlsame section
Create a view
Define a reusable read-only query projection.
OpenIn sheetsql1 tag match
Query a view
Read from the named projection like a table.
OpenIn sheetsql1 tag match