在 MySQL table 中将生成列更改为未生成
Changing generated column to not-generated in MySQL table
我创建了一个包含生成列的 MySQL table:
CREATE TABLE `messages` (
`metadata` JSON NOT NULL,
`aggregate_version` INT(11) UNSIGNED GENERATED ALWAYS AS (metadata->'$._aggregate_version') STORED NOT NULL
);
如何将 aggregate_version
更改为非生成列?列类型应保持不变。
13.1.8.3 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;
参见db-fiddle。
我创建了一个包含生成列的 MySQL table:
CREATE TABLE `messages` (
`metadata` JSON NOT NULL,
`aggregate_version` INT(11) UNSIGNED GENERATED ALWAYS AS (metadata->'$._aggregate_version') STORED NOT NULL
);
如何将 aggregate_version
更改为非生成列?列类型应保持不变。
13.1.8.3 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;
参见db-fiddle。