要在表中添加 MySQL 存储的生成列,我们可以使用与添加列相同的语法,只需在数据类型后添加“AS(表达式)”即可。其语法如下 –
语法
ALTER TABLE table_name ADD COLUMN column_name AS(expression)STORED;
示例
mysql> ALTER TABLE employee_data_stored ADD COLUMN FULLName Varchar(200) AS (CONCAT_WS(" ", 'First_name','Last_name')) STORED; Query OK, 2 rows affected (1.23 sec) Records: 2 Duplicates: 0 Warnings: 0 mysql> Describe employee_data_stored; +------------+--------------+------+-----+---------+------------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+------------------+ | ID | int(11) | NO | PRI | NULL | auto_increment | | First_name | varchar(50) | NO | | NULL | | | Last_name | varchar(50) | NO | | NULL | | | FULL_NAME | varchar(90) | YES | | NULL | STORED GENERATED | | FULLName | varchar(200) | YES | | NULL | STORED GENERATED | +------------+--------------+------+-----+---------+------------------+ 5 rows in set (0.00 sec)原文来自:www.php.cn
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容