简体   繁体   中英

Altering a table column using change

Altering a table column using change is not working but using modify the same query statement works fine.

With change it fails:

alter table users change name varchar(100);

Error Code: 1064 . 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 0.000 sec

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:

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

The syntax for CHANGE is different than 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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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