可以通過一個(gè)示例來說明,在該示例中,我們?cè)诿麨椤皌riangle_stored”的表中創(chuàng)建一個(gè)存儲(chǔ)的生成列。我們知道,存儲(chǔ)生成列可以通過使用關(guān)鍵字“stored”來生成。
示例
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)
登錄后復(fù)制
以上就是MySQL 存儲(chǔ)的生成列如何與數(shù)學(xué)表達(dá)式一起使用?的詳細(xì)內(nèi)容,更多請(qǐng)關(guān)注www.92cms.cn其它相關(guān)文章!