ALTERTABLEemployee_data_storedADDCOLUMNFULLNameVarchar(200)AS(CONCAT_WS("",'First_name',"/> ALTERTABLEemployee_data_storedADDCOLUMNFULLNameVarchar(200)AS(CONCAT_WS("",'First_name',">

Home  >  Article  >  Database  >  How can we change the table to add generated columns from MySQL storage?

How can we change the table to add generated columns from MySQL storage?

王林
王林forward
2023-09-10 12:33:031117browse

我们如何更改表以添加 MySQL 存储的生成列?

To add a generated column of MySQL storage in the table, we can use the same syntax as adding a column, just add "AS (expression)" after the data type That’s it. The syntax is as follows -

Grammar

ALTER TABLE table_name
ADD COLUMN column_name AS(expression)STORED;

Example

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)

The above is the detailed content of How can we change the table to add generated columns from MySQL storage?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete