
- 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 table in MySQL?
To rename a table, the alter and rename commands can be used. These are demonstrated with the help of the following steps −
First, a table is created with the help of the create command. This is given as follows −
mysql> CREATE table Employee -> ( -> EmpId int, -> EmpName varchar(200) -> ); Query OK, 0 rows affected (0.49 sec)
The syntax to change the table name is given as follows −
> alter table yourtableName rename toYourNewtableName;The above syntax is used to change the table name using the following query −
mysql> alter table Employee rename to EmployeeTable; Query OK, 0 rows affected (0.56 sec)
Now that the table name is changed, the select statement is used to see whether the rename operation was successful or not. The query for that is given as follows −
mysql> SELECT * from Employee; ERROR 1146 (42S02): Table 'business.employee' doesn't exist
The above query gives an error as there is no longer a table with the name Employee. The name has been changed to EmployeeTable.
The above query is again executed with the table name ‘EmployeeTable’. This is shown below −
mysql> SELECT * from EmployeeTable; Empty set (0.00 sec)
Now, there is no error for the above query as the table name Employee has been changed to EmployeeTable.
- Related Articles
- Rename a table in MySQL using RENAME TABLE command
- How to rename a column in an existing MySQL table?
- Is there an easy way to rename a table in a MySQL procedure?
- How to SELECT * and rename a column in MySQL?
- Rename column name in MySQL?
- How to rename a username in MongoDB?
- Rename Root @ localhost username in MySQL?
- How can we RENAME an existing MySQL event?
- How to replace a character in a MySQL table?
- Rename all tables and columns to lower case in MySQL?
- How to add a column in a table in MySQL?
- How to rename a file using Python?
- How to rename column names in a Pandas DataFrame?
- How to Rename and Move a File in Golang?
- How to create a MySQL table with InnoDB engine table?
