Skip to content

VIRTUAL

CREATE TABLE employee (
id INT,
first_name VARCHAR(100),
last_name VARCHAR(100),
full_name VARCHAR(255) AS (CONCAT(first_name, ' ', last_name)) VIRTUAL
);
INSERT INTO employee (id, first_name, last_name)
VALUES (1, 'John', 'Doe');
SELECT * FROM employee;
+------+------------+-----------+--------------+
| id | first_name | last_name | full_name |
+------+------------+-----------+--------------+
| 1 | John | Doe | John Doe |
+------+------------+-----------+--------------+

The above example demonstrates the usage of VIRTUAL in MySQL. It creates a VIRTUAL column full_name in the employee table. This column is generated by concatenating first_name and last_name. When a new record is inserted into the table, MySQL automatically calculates and stores the value for the full_name column.