天天看點

Mysql添加虛拟列, 修改虛拟列

-- Mysql添加虛拟列

alter table record_data_store add report_id int(11) generated always as (query->'$.id');

-- 或

alter table record_data_store add column report_id int(11) GENERATED ALWAYS AS (json_extract(`query`,'$.id')) VIRTUAL;

-- 修改虛拟列

alter table record_data_store modify column report_id varchar(255) GENERATED ALWAYS AS (json_extract(`query`,'$.reportType')) VIRTUAL;

-- 删除

ALTER TABLE `record_data_store` DROP COLUMN `report_id`;