Question:
In MySQL Community Server 5.5.27 and later, try renaming a column using the following SQL statement:
<code class="language-sql">ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;</code>
You may encounter the error message:
Error: Please check the documentation for your MySQL server version
Solution:
For MySQL Community Server 5.5.27 and earlier, use the following query to rename columns:
<code class="language-sql">ALTER TABLE tableName CHANGE oldcolname newcolname datatype(length);</code>
Instructions:
TheRENAME COLUMN
syntax is supported in MySQL 8.0 and later. In earlier versions, the CHANGE
syntax was used to rename columns while allowing the data type to be changed.
Additional notes:
In MySQL 8.0 and later, you can use the RENAME COLUMN
syntax to rename a column without changing its data type. The syntax is as follows:
<code class="language-sql">ALTER TABLE table_name RENAME COLUMN old_col_name TO new_col_name;</code>
The above is the detailed content of How Do I Rename a Column in MySQL 5.5.27 and Later Versions?. For more information, please follow other related articles on the PHP Chinese website!