生成列是由已存在的字段通过表达式计算得来的
virtual,即虚拟
类型,字段值不实际存储,当读取行时再计算,虚拟列类型不占存储
stored,即存储
类型,字段值会实际存储起来,当插入或更新时,字段值会计算出来并存储起来
col_name data_type [generated always] as (expr) [virtual | stored] [not null | null] [unique [key]] [[primary] key] [comment 'string']
如:
create table person ( first_name varchar(10) not null comment '名', last_name varchar(10) not null comment '姓', full_name varchar(21) generated always as (concat(first_name,' ',last_name)) stored not null comment '全名' );
再如:
alter table person add full_name_gc varchar(21) generated always as (concat(first_name,'_',last_name)) virtual not null comment '全名(虚拟列)'
详见
如对本文有疑问, 点击进行留言回复!!
MySQL-关系代数-并、交、差、等值连接、自然连接、左连接。。。
【MySQL牛客】10.获取所有非manager的员工emp_no
网友评论