要在表中新增MySQL 虛擬生成列,我們可以使用與新增列相同的語法,只需在資料類型後面新增「AS(表達式)」即可。其語法如下 -
ALTER TABLE table_name ADD COLUMN column_name AS(expression);
mysql> ALTER TABLE employee_data ADD COLUMN FULLName Varchar(200) AS(CONCAT_WS(" ", 'First_name','Last_name')); Query OK, 0 rows affected (0.49 sec) Records: 0 Duplicates: 0 Warnings: 0 mysql> Describe employee_data; +------------+--------------+------+-----+---------+-------------------+ | 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 | VIRTUAL GENERATED | | FULLName | varchar(200) | YES | | NULL | VIRTUAL GENERATED | +------------+--------------+------+-----+---------+-------------------+ 5 rows in set (0.00 sec)
以上是我們如何更改表以新增 MySQL 虛擬生成列?的詳細內容。更多資訊請關注PHP中文網其他相關文章!