您好,欢迎访问一九零五行业门户网

我们如何使用 CREATE TABLE 语句在 MySQL 表中存储多个生成列?

很可能在 mysql 表中添加多个存储的生成列。可以用以下示例来说明:
示例mysql> create table profit1(cost int, price int, profit int as (price-cost) stored, price_revised int as (price-2) stored);query ok, 0 rows affected (0.36 sec)mysql> describe profit1;+---------------+---------+------+-----+---------+------------------+| field | type | null | key | default | extra |+---------------+---------+------+-----+---------+------------------+| cost | int(11) | yes | | null | || price | int(11) | yes | | null | || profit | int(11) | yes | | null | stored generated || price_revised | int(11) | yes | | null | stored generated |+---------------+---------+------+-----+---------+------------------+4 rows in set (0.00 sec)mysql> insert into profit1(cost, price) values(100,110);query ok, 1 row affected (0.09 sec)mysql> insert into profit1(cost, price) values(200,220);query ok, 1 row affected (0.09 sec)mysql> select * from profit1;+------+-------+--------+---------------+| cost | price | profit | price_revised |+------+-------+--------+---------------+| 100 | 110 | 10 | 108 || 200 | 220 | 20 | 218 |+------+-------+--------+---------------+2 rows in set (0.00 sec)
以上就是我们如何使用 create table 语句在 mysql 表中存储多个生成列?的详细内容。
其它类似信息

推荐信息