csdnceshi74
7*4
采纳率50%
2010-10-23 03:35 阅读 293

在 MySQL 中重命名列时出现错误

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)

转载于:https://stackoverflow.com/questions/4002340/error-renaming-a-column-in-mysql

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

8条回答 默认 最新

  • 已采纳
    weixin_41568126 乱世@小熊 2010-10-23 04:08

    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
    点赞 23 评论 复制链接分享
  • csdnceshi74 7*4 2014-08-26 09:22

    There is a syntax problem, because the right syntax to alter command is ALTER TABLE tablename CHANGE OldColumnName NewColunmName DATATYPE;

    点赞 9 评论 复制链接分享
  • csdnceshi69 YaoRaoLov 2010-10-23 03:37

    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

    点赞 8 评论 复制链接分享
  • csdnceshi61 derek5. 2014-10-22 08:48

    With MySQL 5.x you can use:

    ALTER TABLE table_name
    CHANGE COLUMN old_column_name new_column_name DATATYPE NULL DEFAULT NULL;
    
    点赞 8 评论 复制链接分享
  • csdnceshi54 hurriedly% 2014-11-12 10:35

    FOR MYSQL:

    ALTER TABLE `table_name` CHANGE `old_name` `new_name` VARCHAR(255) NOT NULL;
    

    FOR ORACLE:

    ALTER TABLE `table_name` RENAME COLUMN `old_name` TO `new_name`;
    
    点赞 7 评论 复制链接分享
  • csdnceshi80 胖鸭 2014-03-31 02:58

    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

    点赞 3 评论 复制链接分享
  • csdnceshi59 ℙℕℤℝ 2017-05-06 17:08

    Renaming a column in MySQL :

    ALTER TABLE mytable CHANGE current_column_name new_column_name DATATYPE;
    
    点赞 3 评论 复制链接分享
  • csdnceshi58 Didn"t forge 2015-01-29 06:35

    SYNTAX

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

    Example:

    alter table library rename column cost to price;

    点赞 评论 复制链接分享

相关推荐