

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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 Questions & Answers
- 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 multiple files using Python
- Rename multiple files using Java
- Rename Root @ localhost username in MySQL?
- How to rename a file using Python?
- MySQL command to copy table?
- How to rename directory using Python?
- rename() function in PHP
- How to SELECT * and rename a column in MySQL?
- Show constraints on table command in MySQL?
- C# Program to rename a file
Advertisements