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
Release: 2025-01-09 08:02:11
Original
322 people have browsed it

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>
Copy after login
Copy after login

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>
Copy after login

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>
Copy after login
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template