MySQL存储的GENERATED COLUMNS如何与内置函数一起使用?
可以借助一个示例进行说明,在该示例中,我们正在名为“employee_data_stored”的表中创建存储的生成列。众所周知,可以通过使用关键字“存储”来生成存储的生成列。
示例
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); 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'); mysql> INSERT INTO employee_data_stored(first_name, Last_name) values('Raman','Singh'); 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)