Home >Database >Mysql Tutorial >How Do I Rename a Column in MySQL 5.5.27 and Later Versions?

How Do I Rename a Column in MySQL 5.5.27 and Later Versions?

Linda Hamilton
Linda HamiltonOriginal
2025-01-09 08:02:11324browse

How Do I Rename a Column in MySQL 5.5.27 and Later Versions?

Detailed explanation of MySQL database column renaming method

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:

The

RENAME 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn