MySQL 如何将列的类型从 varchar(30) 更改为 varcahar(100)?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6133889/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to change the type of a column from varchar(30) to varcahar(100)?
提问by Mikey
I have a table that describes like this:
我有一张表,描述如下:
mysql> describe easy_table;
+---------------------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------------+--------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| version | bigint(20) | NO | | NULL | |
| account_id | bigint(20) | NO | MUL | NULL | |
| city | varchar(30) | NO | | NULL | |
...
| name | varchar(255) | YES | | NULL | |
| name_two | varchar(255) | YES | | NULL | |
+---------------------+--------------+------+-----+---------+----------------+
13 rows in set (0.03 sec)
I'm trying to make the city varchar bigger to varchar(100) and this line doesn't work
我正在尝试将城市 varchar 放大到 varchar(100) 并且这条线不起作用
alter table easy_table alter column city varchar(100);
this also doesn't work
这也不起作用
alter table easy_table alter column city varchar(100) not null;
I get this error:
我收到此错误:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100)' at line 1
ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,了解在第 1 行的“varchar(100)”附近使用的正确语法
回答by ajreal
alter table easy_table modify column city varchar(100) not null;
回答by john ktejik
Use the Modify keyword, not Alter
使用 Modify 关键字,而不是 Alter
回答by CodeMan
try
尝试
alter table easy_table change city city varchar(100);
回答by Hacker
alter table easy_table modify city VARCHAR(100) ;
must be you command to change the size of the column.
必须是您命令更改列的大小。
Please refer to this page.. This is useful link..
请参阅此页面.. 这是有用的链接..