Home > Database > Mysql Tutorial > body text

How do we change the table to add a MySQL virtual generated column?

王林
Release: 2023-09-09 09:29:07
forward
891 people have browsed it

我们如何更改表以添加 MySQL 虚拟生成列?

To add a MySQL virtual generated column to the table, we can use the same syntax as adding a column, just add "AS (expression)" after the data type, that is Can. The syntax is as follows -

Grammar

ALTER TABLE table_name
ADD COLUMN column_name AS(expression);
Copy after login

Example

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)
Copy after login

The above is the detailed content of How do we change the table to add a MySQL virtual generated column?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!