
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we alter table to add MySQL stored GENERATED COLUMNS?
For adding MySQL stored 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)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)
- Related Articles
- How can we alter table to add MySQL virtual GENERATED COLUMNS?
- How we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we alter a MySQL stored procedure?
- How can we alter a MySQL stored function?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- How MySQL stored GENERATED COLUMNS can work with mathematical expressions?
- 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?
- How MySQL stored GENERATED COLUMNS can work with built-in functions?
- 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 can we add multiple columns, with single command, to an existing MySQL table?
- How can we add a time interval to date stored in a column of MySQL table?
- Can we use ADD and CHANGE with ALTER Statement in MySQL?

Advertisements