EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials MySQL Tutorial MySQL Rename Column
 

MySQL Rename Column

Roja Metla
Article byRoja Metla
EDUCBA
Reviewed byRavi Rathore

Updated May 24, 2023

MySQL Rename Column

 

 

Introduction to MySQL Rename Column

We use the “CHANGE” command and the “ALTER” command to RENAME an existing column. We can change the table names with the command “RENAME”. The MySQL Rename command is used to rename the existing table or an existing column. We can use “Alter” to rename the table, but renaming more than one table can’t be done by “Alter”. We can do this by using the “RENAME” table. Few privileges are essential to the “RENAME” table. ALTER and DROP privilege is necessary for the original table, and CREATE, and INSERT privilege is essential to the New table.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

RENAME can be used to move tables between different databases. To be precise, we can use the RENAME table to move a table from one database to another. RENAME works for a view of the same database, but we can’t perform the rename with the different databases.

Syntax:

To RENAME column from a table

ALTER TABLE<TABLE_NAME>CHANGE<OLD_COLUMNNAME>
<NEW_COLUMNNAME><DATA_TYPE>

To RENAME column from a table:

ALTER TABLE<TABLE_NAME> CHANGE <OLD_COLUMNNAME1><NEW_COLUMNNAME1><DATA_TYPE>,
CHANGE <OLD_COLUMNNAME2><NEW_COLUMNNAME2><DATA_TYPE>,
.
.
.
CHANGE <OLD_COLUMNNAME_N><NEW_COLUMNNAME_N><DATA_TYPE>

To RENAME a single table, we use the below syntax:

RENAME TABLE<old_tablename>TO<New_tablename>

To RENAME multiple tables at a time:

RENAME TABLE<old_tablename1>TO<New_tablename1>,
<old_tablename2>TO<New_tablename2>,
<old_tablename3>TO<New_tablename3>;

Using RENAME between different databases:

RENAME TABLE<Current_database>.<tablename>TO<other_database><tablename>

How to RENAME Column in MYSQL?

Create a test table :

create table test
(
id int
);

Insert data into the test table:

INSERT INTO test VALUES (1);
INSERT INTO test VALUES (2);
INSERT INTO test VALUES (3);
select * from test;

Output:

MySQL Rename Column 1

Let us describe the table and see the output:

DESC test;

Output:

MySQL Rename Column 2

Rename the column from“ID” of INT datatype to “ID” of varchar(20).

ALTER TABLE TEST CHANGE ID ID VARCHAR(10);

Let us describe the table and see the output:

DESC TEST;

Output:

MySQL Rename Column 3

Multiple table RENAME:

create table Data
(
id int,
name varchar(20),
location varchar(20)
);

Insert data into the table:

INSERT INTO DATA VALUES (1,'Rose','United Kingdom');
INSERT INTO DATA VALUES (2,'Jack','United states');
INSERT INTO DATA VALUES (3,'Will','Britain');
select * from DATA;

Output:

MySQL Rename Column 4

Let us describe the table and see the output: –

DESC DATA;

Output:

MySQL Rename Column 5

Now let us change the column “name” of datatype varchar (20) to “name” of datatype varchar(30). Let us increase the size.

ALTER TABLE DATA CHANGE NAME NAME VARCHAR(30),
CHANGE LOCATION LOCATION VARCHAR(30);

Let us describe the table and see the output: –

DESC DATA;

Output:

Describe the table  6

Example of MySQL Rename Column

Let us create the table, insert data into it, and perform rename operation.

create table Collegedata
(
college_id INT,
college_name VARCHAR(30),
No_of_students INT,
Location VARCHAR(20)
);

Insert data into the table:

insert into collegedata values(1890,'Narayana pvt college', 700000,'Hyderabad');
insert into collegedata values(2890,'St.Josephpvt college', 560000,'Kerala');
insert into collegedata values(3890,'Private Plan pvt college', 230000,'Hyderabad');
insert into collegedata values(4890,'Chorniclepvt college', 60000,'Maharastra');
insert into collegedata values(5890,'Number one pvt college', 780000,'Hyderabad');
insert into collegedata values(6890,'Startuppvt college', 500000,'Uttar Pradesh');

Select the data from the table:

select * from collegedata;

Output:

MySQL Rename Column 7

Let us describe the table and see the output: –

DESC collegedata;

Output:

Describe table 8

Now let us change the column “college_name” of datatype varchar (30) to “college_name” of datatype varchar (35). Let us increase our size. The column “location” of datatype varchar (20) to “location” of datatype varchar(30).

ALTER TABLE collegedata CHANGE college_name college_name VARCHAR(35),
CHANGE LOCATION LOCATION VARCHAR(30);

Let us describe the table and see the output:

DESC collegedata;

Output:

Describe the table 9

Recommended Articles

We hope that this EDUCBA information on “MySQL Rename Column” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. MySQL Administration
  2. MySQL Queries
  3. Table in MySQL
  4. MySQL Database Repair

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW