gpt4 book ai didi

mysql - Sql:如何在sql表中添加多个条目

转载 作者:行者123 更新时间:2023-11-29 23:46:02 25 4
gpt4 key购买 nike

请建议如何一次性执行多个命令以在 sql 表中添加条目。

mysql> desc detailed;
+---------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+-------+
| Id | roll(5) | YES | 1 | NULL | |
| Name | varchar(896) | NO | 2 | | |
+---------------------+---------------+------+-----+---------+-------+

预计

+---------------------+---------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+---------------+------+-----+---------+-------+
| Id | roll(5) | YES | 1 | NULL | |
| Name | varchar(896) | NO | 2 | | |
| Value1 | varchar(102) | Yes | | NULL | |
| Value2 | varchar(102) | Yes | | NULL | |
| Value3 | varchar(102) | Yes | | NULL | |
| Value4 | varchar(102) | Yes | | NULL | |
+---------------------+---------------+------+-----+---------+-------+


ALTER TABLE detailed ADD `Value1` varchar(102) DEFAULT NULL;
ALTER TABLE detailed ADD `Value2` varchar(102) DEFAULT NULL;
ALTER TABLE detailed ADD `Value3` varchar(102) DEFAULT NULL;
ALTER TABLE detailed ADD `Value4` varchar(102) DEFAULT NULL;
-- and it's till 50 Value so very time consuming.

谢谢

最佳答案

引用 mysql 文档,您可以使用一个 alter table 命令添加多个列。

You can issue multiple ADD, ALTER, DROP, and CHANGE clauses in a single ALTER TABLE statement, separated by commas. This is a MySQL extension to standard SQL, which permits only one of each clause per ALTER TABLE statement.

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

例如:

ALTER TABLE
detailed
ADD Value1 varchar(102) DEFAULT NULL,
ADD Value2 varchar(102) DEFAULT NULL,
ADD Value3 varchar(102) DEFAULT NULL;

关于mysql - Sql:如何在sql表中添加多个条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25946419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com