Createtableemployee_data_stored(IDINTAUTO_INCREMENTPRIMARYKEY,First_nameVARCHAR(50)NOTNULL,Last_nameVARCHAR(50)NOTNULL,FULL_NAMEVARCHAR(90)GENERATED"/> Createtableemployee_data_stored(IDINTAUTO_INCREMENTPRIMARYKEY,First_nameVARCHAR(50)NOTNULL,Last_nameVARCHAR(50)NOTNULL,FULL_NAMEVARCHAR(90)GENERATED">

Home >Database >Mysql Tutorial >How do MySQL stored GENERATED COLUMNS work with built-in functions?

How do MySQL stored GENERATED COLUMNS work with built-in functions?

WBOY
WBOYforward
2023-08-31 08:25:021253browse

MySQL存储的GENERATED COLUMNS如何与内置函数一起使用?

This can be explained with an example where we create a stored generated column in a table named "employee_data_stored". We know that stored generated columns can be generated by using the keyword "stored".

Example

mysql> Create table employee_data_stored(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)) STORED);
Query OK, 0 rows affected (0.52 sec)

mysql> DESCRIBE employee_data_stored;
+------------+-------------+------+-----+---------+------------------+
| 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    | STORED GENERATED |
+------------+-------------+------+-----+---------+------------------+
4 rows in set (0.00 sec)

mysql> INSERT INTO employee_data_stored(first_name, Last_name) values('Gaurav','Kumar');
Query OK, 1 row affected (0.04 sec)

mysql> INSERT INTO employee_data_stored(first_name, Last_name) values('Raman','Singh');
Query OK, 1 row affected (0.09 sec)

mysql> Select * from employee_data_stored;
+----+------------+-----------+--------------+
| ID | First_name | Last_name | FULL_NAME    |
+----+------------+-----------+--------------+
| 1  | Gaurav     | Kumar     | Gaurav Kumar |
| 2  | Raman      | Singh     | Raman Singh  |
+----+------------+-----------+--------------+
2 rows in set (0.00 sec)

The above is the detailed content of How do MySQL stored GENERATED COLUMNS work with built-in functions?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete