Generated columns

The generated columns are also known as virtual or computed columns. The values of a generated column are computed from an expression included in the column definition. There are two types of generated columns:

  • Virtual: The column will be calculated on the fly when a record is read from a table
  • Stored: The column will be calculated when a new record is written in the table and will be stored in the table as a regular column

Virtual generated columns are more useful than stored generated columns because a virtual column does not take any storage space. You can simulate the behavior of stored generated columns using triggers.

Get MySQL 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.