Gediminas Šedbaras Gediminas Šedbaras - 1 month ago 10
MySQL Question

Changing generated column to not-generated in MySQL table

I've created a MySQL table that contains a generated column:

CREATE TABLE `messages` (
`metadata` JSON NOT NULL,
`aggregate_version` INT(11) UNSIGNED GENERATED ALWAYS AS (metadata->'$._aggregate_version') STORED NOT NULL

How do I change
to be a non-generated column? The column type should stay the same.

Answer Source ALTER TABLE and Generated Columns


  • Stored but not virtual generated columns can be altered to nongenerated columns. The stored generated values become the values of the nongenerated column.



ALTER TABLE `messages`
MODIFY `aggregate_version` INT UNSIGNED NOT NULL;

See db-fiddle.