A virtual column is a table column whose values are calculated automatically using other column values, or another deterministic expression.
Here is the syntax of a virtual column:
column_name [data_type] [GENERATED ALWAYS] AS (expression) [VIRTUAL]
In this syntax:
This statement shows how to define a virtual column in the CREATE TABLE statement:
CREATE TABLE table_name ( ..., virtual_column_name AS (expression) );
And this statement illustrates how to add a virtual column to an existing table using the ALTER TABLE statement:
ALTER TABLE table_name ADD ( virtual_column_name AS (expression) );