[英]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
我正在使用MySql 5.x.
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
可以在一个语句中执行多个表更改,但是MODIFY COLUMN
一次只能在一个列上工作,因此您需要为要更改的每个列指定MODIFY COLUMN
:
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.使用CHANGE或MODIFY时,
column_definition
必须包含应该应用于新列的数据类型和所有属性,而不是索引属性(如PRIMARY KEY或UNIQUE)。 Attributes present in the original definition but not specified for the new definition are not carried forward.原始定义中存在但未为新定义指定的属性不会继续使用。
Use the following syntax: 使用以下语法:
ALTER TABLE your_table
MODIFY COLUMN column1 datatype,
MODIFY COLUMN column2 datatype,
... ... ... ... ...
... ... ... ... ...
Based on that, your ALTER
command should be: 基于此,您的
ALTER
命令应该是:
ALTER TABLE webstore.Store
MODIFY COLUMN ShortName VARCHAR(100),
MODIFY COLUMN UrlShort VARCHAR(100)
Note that: 注意:
MODIFY
statements. MODIFY
声明周围没有第二个括号。 MODIFY
statements for two separate columns. MODIFY
语句。 This is the standard format of the MODIFY
statement for an ALTER
command on multiple columns in a MySQL table. 这是MySQL表中多列上
ALTER
命令的MODIFY
语句的标准格式。
Take a look at the following: http://dev.mysql.com/doc/refman/5.1/en/alter-table.html and Alter multiple columns in a single statement 请查看以下内容: http : //dev.mysql.com/doc/refman/5.1/en/alter-table.html并在单个语句中更改多个列
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.