Home  >  Article  >  Database  >  How to rename columns in existing MySQL table?

How to rename columns in existing MySQL table?

王林
王林forward
2023-09-08 15:21:021044browse

如何重命名现有 MySQL 表中的列?

To rename a column in an existing MySQL table, we can use the ALTER TABLE command with the CHANGE keyword as shown below -

mysql> Alter table Student CHANGE Email Emailid Varchar(30);
Query OK, 5 rows affected (0.38 sec)
Records: 5 Duplicates: 0 Warnings: 0

With the above query, MySQL has changed the name of the "Email" column to "Emailid".

We can specify the same data type and size or a different data type and size using the new column name as shown below -

mysql> Alter table Student CHANGE Emailid Mailid char(35);
Query OK, 5 rows affected (0.29 sec)
Records: 5 Duplicates: 0 Warnings: 0

With the above query, MySQL has changed the column name from "Emailid" to "Mailid" and changed its data type from varchar(30) to char(35).

The above is the detailed content of How to rename columns in existing MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete