
- 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 we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
It is quite possible to add multiple stored generated columns in a MySQL table. It can be illustrated with the following example as follows −
Example
mysql> Create table profit1(cost int, price int, profit int AS (price-cost) STORED, price_revised int AS (price-2) STORED); Query OK, 0 rows affected (0.36 sec) mysql> Describe profit1; +---------------+---------+------+-----+---------+------------------+ | Field | Type | Null | Key | Default | Extra | +---------------+---------+------+-----+---------+------------------+ | cost | int(11) | YES | | NULL | | | price | int(11) | YES | | NULL | | | profit | int(11) | YES | | NULL | STORED GENERATED | | price_revised | int(11) | YES | | NULL | STORED GENERATED | +---------------+---------+------+-----+---------+------------------+ 4 rows in set (0.00 sec) mysql> Insert into profit1(Cost, Price) values(100,110); Query OK, 1 row affected (0.09 sec) mysql> Insert into profit1(Cost, Price) values(200,220); Query OK, 1 row affected (0.09 sec) mysql> Select * from profit1; +------+-------+--------+---------------+ | cost | price | profit | price_revised | +------+-------+--------+---------------+ | 100 | 110 | 10 | 108 | | 200 | 220 | 20 | 218 | +------+-------+--------+---------------+ 2 rows in set (0.00 sec)
- Related Articles
- How can we have multiple virtuals GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- How to create conditions in a MySQL table with multiple columns?
- How can we alter table to add MySQL virtual GENERATED COLUMNS?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- How can we add multiple columns, with single command, to an existing MySQL table?
- SHOW TABLE statement with multiple LIKE values in MySQL?
- How MySQL stored GENERATED COLUMNS can work with mathematical expressions?
- How MySQL stored GENERATED COLUMNS can work with built-in functions?
- Create a Pivot Table with multiple columns – Python Pandas
- Update multiple values in a table with MySQL IF Statement
- How can we set PRIMARY KEY on multiple columns of a MySQL table?
- How can I create a MySQL stored procedure that returns multiple values from a MySQL table?
- Do we have any other statement in MySQL instead of SHOW COLUMNS to get the list of columns in an existing table?
- MySQL Stored Procedure to create a table?

Advertisements