
- 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
Rename column name in MySQL?
To rename column name in MySQL, you need to use the ALTER and CHANGE commands.
Let us first create a table −
mysql> create table DemoTable796 ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, Name varchar(100), StudentAge int ); Query OK, 0 rows affected (0.56 sec)
Let us check the description of table −
mysql> desc DemoTable796;
This will produce the following output -
+------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | Name | varchar(100) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +------------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
Following is the query to rename column name in MySQL −
mysql> alter table DemoTable796 change Name StudentName varchar(100); Query OK, 0 rows affected (0.29 sec) Records: 0 Duplicates: 0 Warnings: 0
Let us check the description of table once again −
mysql> desc DemoTable796;
This will produce the following output -
+-------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------------+--------------+------+-----+---------+----------------+ | StudentId | int(11) | NO | PRI | NULL | auto_increment | | StudentName | varchar(100) | YES | | NULL | | | StudentAge | int(11) | YES | | NULL | | +-------------+--------------+------+-----+---------+----------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to SELECT * and rename a column in MySQL?
- How to rename a column in an existing MySQL table?
- Rename column name with an index number of the CSV file in Pandas
- Rename a table in MySQL using RENAME TABLE command
- Wildcards in column name for MySQL?
- Display distinct column name in MySQL
- Python - Rename column names by index in a Pandas DataFrame without using rename()
- Rename Root @ localhost username in MySQL?
- Fetch a specific column value (name) in MySQL
- How to rename a table in MySQL?
- How to rename column names in a Pandas DataFrame?
- MySQL query to display columns name first name, last name as full name in a single column?
- How to rename a single column in an R data frame?
- How to select a column name with spaces in MySQL?
- Updating a MySQL column that contains dot (.) in its name?

Advertisements