重命名 MySQL 中的列
我正在尝试使用此 SQL 表达式重命名 MySQL 社区服务器 5.5.27 中的列:
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
我也试过
ALTER TABLE table_name RENAME old_col_name TO new_col_name;
但它说:
<块引用>错误:检查与您的 MySQL 服务器版本相对应的手册
解决方案使用以下查询:
ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length);
RENAME
函数用于 Oracle 数据库.
ALTER TABLE tableName RENAME COLUMN oldcolname TO newcolname datatype(length);
@lad2025 在下面提到了它,但我认为添加他所说的内容会很好.谢谢@lad2025!
您可以使用 MySQL 8.0 中的 RENAME COLUMN
重命名您需要重命名的任何列.
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
<块引用>
ALTER TABLE 语法:重命名列:
- 可以更改列名称,但不能更改其定义.
- 在不更改其定义的情况下重命名列比 CHANGE 更方便.
I am trying to rename a column in MySQL community server 5.5.27 using this SQL expression:
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
I also tried
ALTER TABLE table_name RENAME old_col_name TO new_col_name;
But it says:
Error: check the Manual that corresponds to your MySQL server version
解决方案
Use the following query:
ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length);
The RENAME
function is used in Oracle databases.
ALTER TABLE tableName RENAME COLUMN oldcolname TO newcolname datatype(length);
@lad2025 mentions it below, but I thought it'd be nice to add what he said. Thank you @lad2025!
You can use the RENAME COLUMN
in MySQL 8.0 to rename any column you need renamed.
ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;
ALTER TABLE Syntax: RENAME COLUMN:
- Can change a column name but not its definition.
- More convenient than CHANGE to rename a column without changing its definition.
相关文章