- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we alter table to add MySQL virtual GENERATED COLUMNS?
For adding MySQL virtual GENERATED COLUMNS in a table, we can use the same syntax as adding a column just adding “AS(expression)” after the data type. Its syntax would be as follows −
Syntax
ALTER TABLE table_name ADD COLUMN column_name AS(expression);
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)
- Related Articles
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- How MySQL virtual GENERATED COLUMNS can work with mathematical expressions?
- How Can MySQL virtual GENERATED COLUMNS work with built-in functions?
- How can we use MySQL ALTER TABLE command for adding comments on columns?
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- Can we alter order of columns in MySQL?
- How can we add columns with default values to an existing MySQL table?
- How can we add values into the columns of a MySQL table?
- How we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we add multiple columns, with single command, to an existing MySQL table?
- Can we use ADD and CHANGE with ALTER Statement in MySQL?
- How can we alter a MySQL stored procedure?
- How can we alter a MySQL stored function?
- ALTER TABLE to add a composite primary key in MySQL?

Advertisements