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!