mysql - 如何更改超过 1 列的表列数据类型?

例如:

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

但上述方法不起作用。我正在使用 MySql 5.x

最佳答案

ALTER TABLE可以在一个语句中进行多个表更改,但 MODIFY COLUMN 一次只能处理一列,因此您需要为要更改的每一列指定 MODIFY COLUMN :

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

另外,请注意手册中的此警告:

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.

https://stackoverflow.com/questions/3773480/

相关文章:

mysql - 如何使用时区信息在 MySQL 中存储日期时间

mysql - 获取不带表格格式的SQL查询结果

mysql - 我们如何区分 LEFT OUTER JOIN 与 Left Join

mysql - 如何在 Mysql Workbench GUI 中查看表格内容?

mysql - 将表从 Amazon RDS 导出到 CSV 文件

mysql - 将主机访问权限重新分配给 MySQL 用户

mysql - phpmyadmin.pma_table_uirefs 不存在

sql - MySQL:ORDER BY RAND() 的替代方案

mysql - unix 时间戳应该如何存储在 int 列中?

mysql - 将聊天消息存储在数据库中的最佳方法?