简体   繁体   English

使用更改来更改表列

[英]Altering a table column using change

Altering a table column using change is not working but using modify the same query statement works fine. 使用change更改表列不起作用,但是使用modify相同的查询语句可以正常工作。

With change it fails: 更改将导致失败:

alter table users change name varchar(100);

Error Code: 1064 . 错误代码:1064 You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'varchar(100)' at line 1 0.000 sec 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在行1 0.000秒处在'varchar(100)'附近使用

With Modify it works. 使用修改,它可以工作。

alter table users modify name varchar(100);

If you use CHANGE then you have to specify a new name for the column, so the following should work: 如果使用CHANGE则必须为该列指定一个新名称,因此以下各项应适用:

alter table users change name newname varchar(100);

Look at the alter specification for CHANGE : http://dev.mysql.com/doc/refman/5.1/en/alter-table.html 查看CHANGE的alter规范: http : //dev.mysql.com/doc/refman/5.1/en/alter-table.html

The syntax for CHANGE is different than MODIFY . CHANGE的语法不同于MODIFY From the documentation : 文档中

CHANGE [COLUMN] old_col_name new_col_name column_definition

So, in your case, you should use: 因此,在您的情况下,您应该使用:

alter table users change name name varchar(100);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM