
- 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 a table in MySQL using RENAME TABLE command
To rename a table in MySQL, below is the syntax −
rename table yourOldTableName to yourNewTableName ;
Let us first create a table −
mysql> create table DemoTable1 ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserName varchar(100), UserAge int, UserCountryName varchar(100) ); Query OK, 0 rows affected (1.29 sec)
Let us check the description of the table −
mysql> desc DemoTable1;
This will produce the following output −
+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(100) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | UserCountryName | varchar(100) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.20 sec)
Now, we will rename a table in MySQL using RENAME command −
mysql> rename table DemoTable1 to DemoTable2; Query OK, 0 rows affected (1.22 sec)
Let us check the description of the table once again −
mysql> desc DemoTable2;
This will produce the following output −
+-----------------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+--------------+------+-----+---------+----------------+ | Id | int(11) | NO | PRI | NULL | auto_increment | | UserName | varchar(100) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | UserCountryName | varchar(100) | YES | | NULL | | +-----------------+--------------+------+-----+---------+----------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to rename a table in MySQL?
- How to rename a column in an existing MySQL table?
- Is there an easy way to rename a table in a MySQL procedure?
- Rename column name in MySQL?
- Python - Rename column names by index in a Pandas DataFrame without using rename()
- Rename Root @ localhost username in MySQL?
- Rename multiple files using Python
- Rename multiple files using Java
- How to rename a file using Python?
- How to SELECT * and rename a column in MySQL?
- MySQL command to copy table?
- How to rename directory using Python?
- rename() function in PHP
- Show constraints on table command in MySQL?
- How can we RENAME an existing MySQL event?

Advertisements