# A Complete Guide to Generated Columns in MySQL

## Metadata
- Author: [[Arctype Team]]
- Full Title: A Complete Guide to Generated Columns in MySQL
- Category: #articles
- Summary: MySQL generated columns automatically create data in a table based on other columns without manual input. They come in two types: virtual (calculated on the fly) and stored (saved on disk), each with pros and cons. Using generated columns simplifies queries, speeds up data retrieval, and helps create functional indexes.
- URL: https://dev.to/arctype/a-complete-guide-to-generated-columns-in-mysql-2lnb
## Highlights
- What is a MySQL Generated Column?
A generated column is similar to a normal column, but you cannot change its value manually. This is because an expression defines how to generate the value of a generated column based on the other values that are read from the other columns of the same row. ([View Highlight](https://read.readwise.io/read/01m2rfg0bmvjmge9n7d3dchwe1))
- its definition cannot involve `JOIN` statements. ([View Highlight](https://read.readwise.io/read/01m2rfhg8dwe1n64mn2mn1k0p7))
- What Types of Generated Columns Exist in MySQL?
As explained earlier, you can define a generated column as VIRTUAL or STORED. Let’s now take a closer look at these two types.
[](https://dev.to/arctype/a-complete-guide-to-generated-columns-in-mysql-2lnb/#virtual-generated-columns)Virtual generated columns
MySQL does not store a generated column marked as VIRTUAL. This means that MySQL evaluates its value on the fly when required. This typically happens immediately after any `BEFORE` query is triggered. In other terms, a virtual generated column takes up no storage space.
[](https://dev.to/arctype/a-complete-guide-to-generated-columns-in-mysql-2lnb/#stored-generated-columns)Stored generated columns
MySQL stores any generated column marked as STORED. This means that MySQL takes care of evaluating its value and storing it on the disk every time you insert or update a row. In other terms, a stored column requires storage space as if it was a normal column. ([View Highlight](https://read.readwise.io/read/01m2rfpwq77n61ws9prk3ctw8p))