Gediminas Ć edbaras Gediminas Ć edbaras - 10 months ago 82
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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download