MySQL Generated Columns
MySQL Generated Columns is a SQL data type in the MySQL Specific category. MySQL 5.7+: computed column that derives its value from an expression. VIRTUAL (computed on read) or STORED (stored on disk). The syntax is col type GENERATED ALWAYS AS (expression) [STORED | VIRTUAL];. It returns generated column. A typical example: CREATE TABLE employees ( first_name VARCHAR(50), last_name VARCHAR(50), full_name VARCHAR(101) GENERATED ALWAYS AS (CONCAT(first_name, ' ', last_name)) VIRTUAL, salary DECIMAL(10,2), bonus DECIMAL(10,2), total_comp DECIMAL(10,2) GENERATED ALWAYS AS (salary + COALESCE(bonus, 0)) STORED ); -- VIRTUAL: no storage, computed on read -- STORED: stored, takes space but can be indexed SELECT full_name, total_comp FROM employees; A close relative is AUTO_INCREMENT, which mySQL auto-generates sequential integer values for this column. Commonly used with PRIMARY KEY. A close relative is ENGINE, which specifies the MySQL storage engine. InnoDB (default) supports transactions and foreign keys. MyISAM is faster for read-heavy.