Home > Database > Mysql Tutorial > body text

How do MySQL stored generated columns work with mathematical expressions?

PHPz
Release: 2023-09-13 15:09:02
forward
537 people have browsed it

MySQL 存储的生成列如何与数学表达式一起使用?

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

Example

mysql> Create table triangle_stored(SideA DOUBLE, SideB DOUBLE, SideC DOUBLE AS (SQRT(SideA * SideB + SideB * SideB)) STORED);
Query OK, 0 rows affected (0.47 sec)

mysql> Describe triangle_stored;
+-------+--------+------+-----+---------+------------------+
| Field | Type   | Null | Key | Default | Extra            |
+-------+--------+------+-----+---------+------------------+
| SideA | double | YES  |     | NULL    |                  |
| SideB | double | YES  |     | NULL    |                  |
| SideC | double | YES  |     | NULL    | STORED GENERATED |
+-------+--------+------+-----+---------+------------------+
3 rows in set (0.00 sec)

mysql> INSERT INTO triangle_stored(SideA, SideB) Values(1,1),(3,4),(6,8);
Query OK, 3 rows affected (0.09 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> Select * from triangle_stored;
+-------+-------+--------------------+
| SideA | SideB | SideC              |
+-------+-------+--------------------+
|     1 |     1 | 1.4142135623730951 |
|     3 |     4 | 5.291502622129181  |
|     6 |     8 | 10.583005244258363 |
+-------+-------+--------------------+
3 rows in set (0.00 sec)
Copy after login

The above is the detailed content of How do MySQL stored generated columns work with mathematical expressions?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template