MySQL database column renaming method
When renaming table columns in MySQL Community Server 5.5.27, users may encounter errors, especially when using the following SQL statement:
<code class="language-sql">ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;</code>
and
<code class="language-sql">ALTER TABLE table_name RENAME old_col_name TO new_col_name;</code>
These statements may be invalid in some MySQL versions. You need to consult the manual according to the specific version.
Solution
To successfully rename a column in MySQL Community Server 5.5.27, use the following query:
<code class="language-sql">ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length);</code>
It should be noted that the RENAME
function is used in Oracle database. However, in MySQL 8.0 and later, any column can be renamed using the RENAME COLUMN
syntax:
<code class="language-sql">ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;</code>
RENAME COLUMN syntax detailed explanation
RENAME COLUMN
in MySQL Syntax:
The above is the detailed content of How Do I Rename a MySQL Column in Versions 5.5 and 8.0?. For more information, please follow other related articles on the PHP Chinese website!