MySQL Alter Table Statement Exercises: Rename the table countries to country_new
MySQL Alter Table Statement: Exercise-1 with Solution
Write a MySQL statement to rename the table countries to country_new.
Here is the list of tables.
+---------------+ | Tables_in_hrr | +---------------+ | countries | | departments | | dup_countries | | employees | | jobs | +---------------+
Code:
-- This SQL statement is used to rename the table 'countries' to 'country_new'.
-- It alters the structure of the database by changing the table name.
ALTER TABLE countries
-- Rename the table 'countries' to 'country_new'.
RENAME country_new;
Let execute the above code in MySQL command prompt
Now, after execute the command see the list of tables.
+---------------+
| Tables_in_hrr |
+---------------+
| country_new |
| departments |
| dup_countries |
| employees |
| jobs |
+---------------+
Explanation:
Here's a brief explanation of the above MySQL code:
- ALTER TABLE countries: This part of the statement indicates that you want to make changes to the structure of the 'countries' table.
- RENAME country_new;: This specifies the action to be taken. It renames the 'countries' table to 'country_new'.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: MySQL Alter Table
Next: Write a SQL statement to add a column region_id to the table locations.
What is the difficulty level of this exercise?
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics