
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to rename a column in an existing MySQL table?
To rename a column in an existing MySQL table we can use ALTER TABLE command with CHANGE keyword as follows −
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 help of query above, MySQL has changed the name of column ‘Email’ to ‘Emailid’.
We can specify the same data type & size or different data type & size with new column name as follows −
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 help of query above, MySQL has changed the name of the column from ‘Emailid’ to ‘Mailid’ along with its data type from varchar(30) to char(35).
- Related Articles
- How can we RENAME an existing MySQL event?
- Adding new enum column to an existing MySQL table?
- How can I drop an existing column from a MySQL table?
- How to rename a table in MySQL?
- Rename a table in MySQL using RENAME TABLE command
- How to add column to an existing table in PostgreSQL?
- How can we apply a NOT NULL constraint to a column of an existing MySQL table?
- How to SELECT * and rename a column in MySQL?
- How can I change the name of an existing column from a MySQL table?
- Inserting data into a new column of an already existing table in MySQL?
- How to add columns to an existing MySQL table?
- How can we put comments in a column of existing MySQL table?
- How to generate a “create table” command based on an existing table in MySQL?
- How can we remove NOT NULL constraint from a column of an existing MySQL table?
- How can we remove PRIMARY KEY constraint from a column of an existing MySQL table?

Advertisements