0

Kindly advice how to execute multiple commands in 1 go for adding entries in sql table.

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

Expected

+---------------------+---------------+------+-----+---------+-------+
| 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. 

Thanks,

1
  • 1
    I have a suspicion, that something is wrong with your DB structure. Why do you need so many similar columns? Commented Sep 20, 2014 at 7:38

1 Answer 1

0

Referring to the mysql documentation you can add multiple columns with one alter table command.

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

For example:

ALTER TABLE
    detailed
ADD Value1 varchar(102) DEFAULT NULL,
ADD Value2 varchar(102) DEFAULT NULL,
ADD Value3 varchar(102) DEFAULT NULL;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.