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)
从carmake 输出中 选择不同的国家/地区 :
+----------------+ | 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`;