Search code examples
mysqlcommand-lineadditionalter

MySQL: how not to repeat the column_definition for each column when adding multiple columns


I am running mysql 5.0. How do I write an SQL query to add new coloumns (all of the same type) to a table without repeating the coloumn type for each of them.

For example:

mysql --user=db_user --password=db_pwd -e "ALTER TABLE db_name.db_table \
ADD ( \
new_column_1 TEXT NOT NULL,
new_column_2 TEXT NOT NULL)"

In the example above the common type is 'TEXT NOT NULL'. Note that the actual scenario has a lot more coloumns and not just 2 as specified in the example.

Summarily, is there a way to 'factorize' the common type?


Solution

  • You cannot. Each column name should be followed with its definition.