This article will make us understand how we can rename the table in MySQL.
How we can rename a table in MySQL
To understand how we can rename the table in MySQL, we will first open the terminal and go to the MySQL environment by using the command
Once we are in MySQL, we should list the databases we have already created in MySQL as
In the output, we can see the list of databases and can also see the database “Organization” which has been created by us. To access this database, we will execute the following command with the database name.
Once we are in the database, display the list of tables of this database.
Open the table, “Employees_data” using the command DESCRIBE with the name of the table.
In the output, a table has been displayed. Now if we want to change the name of the table we can change it by command whose general syntax is.
In our example, we use this command as:
The name has been changed now to verify it we will open the table by its new name.
We can also rename the table by using the ALTER command. The general structure of the command will be.
In our case, it will be as:
For the verification purpose, we again display the table by using the new name as:
We can also use ALTER TABLE command as:
In our example, it will be used as:
For the display of the newly named table:
Now we will exit the MySQL environment:
Conclusion
In this article, we have discussed with some examples, a technique of how to rename a table works in MySQL. We rename a table with the command of “RENAME” as well as with the command of “ALTER”. I hope this article will help you in understanding the technique of “renaming a table”.