Error renaming a column in MySQL

2019-01-04 15:58发布

How do I rename a column in table xyz? The columns are:

Manufacurerid, name, status, AI, PK, int

I want to rename to manufacturerid

I tried using PHPMyAdmin panel, but I get this error:

MySQL said: Documentation
#1025 - Error on rename of '.\shopping\#sql-c98_26' to '.\shopping\tblmanufacturer' (errno: 150)

8条回答
虎瘦雄心在
2楼-- · 2019-01-04 16:33

The standard Mysql rename statement is:

ALTER [ONLINE | OFFLINE] [IGNORE] TABLE tbl_name 
CHANGE [COLUMN] old_col_name new_col_name column_definition 
[FIRST|AFTER col_name]

for this example:

ALTER TABLE xyz CHANGE manufacurerid manufacturerid datatype(length)

Reference: MYSQL 5.1 ALTER TABLE Syntax

查看更多
smile是对你的礼貌
3楼-- · 2019-01-04 16:33

SYNTAX

alter table table_name rename column old column name to new column name;

Example:

alter table library rename column cost to price;

查看更多
手持菜刀,她持情操
4楼-- · 2019-01-04 16:34

Lone Ranger is very close... in fact, you also need to specify the datatype of the renamed column. For example:

ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT;

Remember :

  • Replace INT with whatever your column data type is (REQUIRED)
  • Tilde/ Backtick (`) is optional
查看更多
▲ chillily
5楼-- · 2019-01-04 16:35

EDIT

You can rename fields using:

ALTER TABLE xyz CHANGE manufacurerid manufacturerid INT

http://dev.mysql.com/doc/refman/5.1/en/alter-table.html

查看更多
甜甜的少女心
6楼-- · 2019-01-04 16:42

With MySQL 5.x you can use:

ALTER TABLE table_name
CHANGE COLUMN old_column_name new_column_name DATATYPE NULL DEFAULT NULL;
查看更多
乱世女痞
7楼-- · 2019-01-04 16:48

Renaming a column in MySQL :

ALTER TABLE mytable CHANGE current_column_name new_column_name DATATYPE;
查看更多
登录 后发表回答