A Column from a Formula
A generated column, also called a computed column, holds a value derived from other columns by an expression you define. You never insert into it directly. The database fills it from the rule, like a full name built from first and last name.
Stored vs Virtual
- A stored generated column saves the computed value on disk, so reads are fast but writes do a little extra work.
- A virtual generated column computes the value on each read, saving space but spending time at query time.
Why They Help
- They keep derived data consistent, since the rule lives in one place.
- A stored generated column can be indexed, so you can search on the derived value quickly.
- They simplify queries because the calculation is defined once.
A Limit
The expression usually must be deterministic and may only reference columns in the same row, so it cannot pull from other tables or use random values.
Key idea
A generated column derives its value from other columns by a rule, keeping data consistent and, when stored, allowing the derived value to be indexed.