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

How to rename columns in existing MySQL table?

王林
Release: 2023-09-08 15:21:02
forward
1052 people have browsed it

如何重命名现有 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
Copy after login

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

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!

source:tutorialspoint.com
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template