Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I Alter Table Column datatype on more than 1 column?

For example:

ALTER TABLE webstore.Store MODIFY COLUMN (   ShortName VARCHAR(100),   UrlShort VARCHAR(100) ); 

The above however does not work. I am using MySql 5.x

like image 989
JoJo Avatar asked Sep 22 '10 20:09

JoJo


People also ask

Can we modify multiple columns in SQL?

In SQL, sometimes we need to write a single query to update the values of all columns in a table. We will use the UPDATE keyword to achieve this.

Can we modify more than one column in ALTER TABLE?

ALTER TABLE can do multiple table alterations in one statement, but MODIFY COLUMN can only work on one column at a time, so you need to specify MODIFY COLUMN for each column you want to change: ALTER TABLE webstore.


1 Answers

ALTER TABLE can do multiple table alterations in one statement, but MODIFY COLUMN can only work on one column at a time, so you need to specify MODIFY COLUMN for each column you want to change:

ALTER TABLE webstore.Store   MODIFY COLUMN ShortName VARCHAR(100),   MODIFY COLUMN UrlShort VARCHAR(100); 

Also, note this warning from the manual:

When you use CHANGE or MODIFY, column_definition must include the data type and all attributes that should apply to the new column, other than index attributes such as PRIMARY KEY or UNIQUE. Attributes present in the original definition but not specified for the new definition are not carried forward.

like image 54
Daniel Vandersluis Avatar answered Oct 22 '22 00:10

Daniel Vandersluis