PostgreSQL Alter Table: Alter a table to change its name
1. Write a SQL statement to rename the table countries to country_new.
Here is the list of tables.
tablename | tableowner ---------------+------------ orders | postgres employees | postgres job_history | postgres jobs | postgres locations | postgres regions | postgres countries | postgres (7 rows)
Sample Solution:
Code:
ALTER TABLE countries RENAME TO country_new;
Output:
Now, after execute the command see the list of tables.
tablename | tableowner ---------------+------------ orders | postgres employees | postgres job_history | postgres jobs | postgres locations | postgres regions | postgres country_new | postgres (7 rows)
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: PostgreSQL Alter Table - Exercises, Practice, Solution
Next: Write a SQL statement to add a column region_id to the table locations.
What is the difficulty level of this exercise?
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://w3resource.com/postgresql-exercises/alter-table/alter-table-exercise-1.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics