请建议如何在1中执行多个命令,以便在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 NUL
Value2 varchar(102) Yes NUL
Value3 varchar(102) Yes NUL
Value4 varchar(102) Yes NUL
+---------------------+---------------+------+-----+---------+-------+
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.
谢谢,
答案 0 :(得分:0)
参考mysql文档,您可以使用一个alter table
命令添加多个列。
您可以在单个ALTER TABLE语句中发出多个ADD,ALTER,DROP和CHANGE子句,以逗号分隔。这是标准SQL的MySQL扩展,它只允许每个ALTER TABLE语句中的一个子句。
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;