要在表中添加 MySQL 存儲的生成列,我們可以使用與添加列相同的語法,只需在數(shù)據(jù)類型后添加“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)
登錄后復制
以上就是我們?nèi)绾胃谋硪蕴砑?MySQL 存儲的生成列?的詳細內(nèi)容,更多請關注www.92cms.cn其它相關文章!