MySQL 参考手册没有提供关于如何执行此操作的明确示例。
我有一个 ENUM 类型的国家名称列,我需要添加更多国家。实现此目的的正确 MySQL 语法是什么?
这是我的尝试:
ALTER TABLE carmake CHANGE country country ENUM('Sweden','Malaysia');
我得到的错误是:ERROR 1265 (01000): Data truncated for column 'country' at row 1.
ERROR 1265 (01000): Data truncated for column 'country' at row 1.
该country列是上述语句中的 ENUM 类型列。
country
显示创建表 输出:
mysql> SHOW CREATE TABLE carmake; +---------+---------------------------------------------------------------------+ | Table | Create Table +---------+---------------------------------------------------------------------+ | carmake | CREATE TABLE `carmake` ( `carmake_id` tinyint(4) NOT NULL AUTO_INCREMENT, `name` tinytext, `country` enum('Japan','USA','England','Australia','Germany','France','Italy','Spain','Czech Republic','China','South Korea','India') DEFAULT NULL, PRIMARY KEY (`carmake_id`), KEY `name` (`name`(3)) ) ENGINE=InnoDB AUTO_INCREMENT=49 DEFAULT CHARSET=latin1 | +---------+---------------------------------------------------------------------+ 1 row in set (0.00 sec)
从汽车制造商 输出中选择不同的国家:
+----------------+ | country | +----------------+ | Italy | | Germany | | England | | USA | | France | | South Korea | | NULL | | Australia | | Spain | | Czech Republic | +----------------+
ALTER TABLE `table_name` MODIFY COLUMN `column_name2` enum( 'existing_value1', 'existing_value2', 'new_value1', 'new_value2' ) NOT NULL AFTER `column_name1`;