
- 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 MySQL virtual GENERATED COLUMNS work with built-in functions?
It can be illustrated with the help of an example in which we are creating a virtual generated column in the table named ‘employee_data’. As we know that virtual generated column can be generated with or without using the keyword ‘virtual’.
Example
mysql> Create table employee_data(ID INT AUTO_INCREMENT PRIMARY KEY, First_name VARCHAR(50) NOT NULL, Last_name VARCHAR(50) NOT NULL, FULL_NAME VARCHAR(90) GENERATED ALWAYS AS(CONCAT(First_name,'',Last_name))); Query OK, 0 rows affected (0.55 sec) mysql> DESCRIBE employee_data; +------------+-------------+------+-----+---------+-------------------+ | 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 | VIRTUAL GENERATED | +------------+-------------+------+-----+---------+-------------------+ 4 rows in set (0.00 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Yashpal','Sharma'); Query OK, 1 row affected (0.09 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Krishan','Kumar'); Query OK, 1 row affected (0.09 sec) mysql> INSERT INTO employee_data(first_name, Last_name) values('Rakesh','Arora'); Query OK, 1 row affected (0.08 sec) mysql> Select * from employee_data; +----+------------+-----------+----------------+ | ID | First_name | Last_name | FULL_NAME | +----+------------+-----------+----------------+ | 1 | Yashpal | Sharma | Yashpal Sharma | | 2 | Krishan | Kumar | Krishan Kumar | | 3 | Rakesh | Arora | Rakesh Arora | +----+------------+-----------+----------------+ 3 rows in set (0.00 sec)
- Related Articles
- How MySQL stored GENERATED COLUMNS can work with built-in functions?
- How MySQL virtual GENERATED COLUMNS can work with mathematical expressions?
- How MySQL stored GENERATED COLUMNS can work with mathematical expressions?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- How can we alter table to add MySQL virtual GENERATED COLUMNS?
- 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 we have multiple stored GENERATED COLUMNS in MySQL table with CREATE TABLE statement?
- How can MySQL work with PHP programming language?
- What are the different types of MySQL GENERATED COLUMNS?
- How MySQL aggregate functions can be combined with MySQL IF() function?
- Can a C++ virtual functions have default parameters?
- Built-in Tuple Functions in Python
- How are virtual functions implemented in C++?
- How can we combine functions in MySQL?

Advertisements