重命名 MySQL 中的列时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4002340/
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
Error renaming a column in MySQL
提问by Bharanikumar
How do I rename a column in table xyz
? The columns are:
如何重命名表中的列xyz
?列是:
Manufacurerid, name, status, AI, PK, int
I want to rename to manufacturerid
我想重命名为 manufacturerid
I tried using PHPMyAdmin panel, but I get this error:
我尝试使用 PHPMyAdmin 面板,但出现此错误:
MySQL said: Documentation
#1025 - Error on rename of '.\shopping\#sql-c98_26' to '.\shopping\tblmanufacturer' (errno: 150)
回答by Matt Diamond
Lone Ranger is very close... in fact, you also need to specify the datatype of the renamed column. For example:
Lone Ranger 非常接近……其实你还需要指定重命名列的数据类型。例如:
ALTER TABLE `xyz` CHANGE `manufacurerid` `manufacturerid` INT;
Remember :
记住 :
- Replace INT with whatever your column data type is (REQUIRED)
- Tilde/ Backtick (`) is optional
- 将 INT 替换为您的列数据类型(必需)
- 波浪号/反引号 (`) 是可选的
回答by dongpf
The standard Mysql rename statement is:
标准的 Mysql 重命名语句是:
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
回答by mahbub_siddique
FOR MYSQL:
对于 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`;
回答by Lone Ranger
EDIT
编辑
You can rename fields using:
您可以使用以下方法重命名字段:
ALTER TABLE xyz CHANGE manufacurerid manufacturerid INT
回答by Darshan
There is a syntax problem, because the right syntax to alter command is ALTER TABLE tablename CHANGE OldColumnName NewColunmName DATATYPE;
存在语法问题,因为更改命令的正确语法是 ALTER TABLE tablename CHANGE OldColumnName NewColunmName DATATYPE;
回答by MIKE KIM
With MySQL 5.x you can use:
使用 MySQL 5.x,您可以使用:
ALTER TABLE table_name
CHANGE COLUMN old_column_name new_column_name DATATYPE NULL DEFAULT NULL;
回答by Hasib Kamal
Renaming a column in MySQL :
重命名 MySQL 中的列:
ALTER TABLE mytable CHANGE current_column_name new_column_name DATATYPE;
回答by vaquar khan
ALTER TABLE CHANGE ;
更改表更改;
Example:
例子:
ALTER TABLE global_user CHANGE deviceToken deviceId VARCHAR(255) ;
回答by Abinaya
SYNTAX
句法
alter table table_namerename column old column nameto new column name;
alter table table_name将列旧列名重命名为新列名;
Example:
例子:
alter table libraryrename column costto price;
更改表库将列成本重命名为价格;