Rename A Column In MySQL

Rename Column MySQL

This is a quick tutorial on how you can rename a column name in MySQL databases. Steps to rename column with ALTER TABLE statement are illustrated.

Rename Column ALTER TABLE Query Syntax

The most generic query to rename a column of a MySQL database table is written below.

You may or may not need to use the backticks (`). Some versions of MySQL may not support backticks. So, you might directly write the column names without any backticks or can use the single or double-quotes. All you’ve to do is try.

Rename MySQL Column Example

In my demo database, I have got a table named books in which I have got a column name. Now I am running the following query to the change the column name to book_name. The data type that I am specifying here is TEXT and it need not any length specification.

Query.

Note. I’ve tried running the query without specifying the data type assuming if it can detect in case there’s no data type change, but it does not work. So, you must specify the data type.

Result.

Column Rename Example MySQL

In my Testing, the query does not execute and displayed an error message when I tried to write the column names in single or double-quotes. But without any quotes or with backticks, it worked as expected.

RENAME Function In ORACLE Databases

You can make use of the RENAME function in case you’re working with ORACLE Databases. The syntax of the ALTER TABLE query for the same is written below.

Note. Here you have to write the column name in double quotes and instead of the CHANGE keyword, here the RENAME COLUMN keyword is used. Also, the old and new column names are separated by a TO keyword.

Another Method For MySQL 8.0

Sources suggest that in MySQL 8.0, you can use the following syntax:

This syntax also doesn’t require the need to mentioning the data type as our goal is to change only the name and not to do anything with the current data type.

Renaming Column Name Using phpMyAdmin GUI

You can use the phpMyAdmin GUI to change the column name really quick. The steps are mentioned below.

  1. In the phpMyAdmin Dashboard, select the database and the table of which column you want to rename.

PhpMyAdmin GUI Column Rename

  1. Navigate to the Structure tab as illustrated by #2 in the screenshot given above.

PhpMyAdmin GUI Column Rename Step 3 & 4

  1. Now in the Structure tab, choose to view the Table structure and here click on the Change option corresponding to the column row for which you want to perform the rename operation.

PhpMyAdmin GUI Column Rename Final Step

  1. Change the name here in the Name field and click on the Save button to make the changes.

This way you will be able to successfully change the column name with the phpMyAdmin GUI.

I hope you find this guide useful. If so, do share it with others who are willing to learn SQL. If you have any questions related to this article, feel free to ask them in the comments section.

Helpful Associated Guides.

Also, don’t forget to Subscribe to WTMatter!

Subscribe To WTMatter!

Receive updates of our latest articles via email. Enter your email address below to get started.

Leave a Reply

Your email address will not be published. Required fields are marked *