PostgreSQL Create Table: Create a duplicate copy of countries table including structure and data by name dup_countries
4. Write a SQL statement to create a duplicate copy of countries table, including structure and data by name dup_countries.
Sample Solution:
Code:
CREATE TABLE dup_countries
AS SELECT *
FROM countries;
Output:
postgres=# CREATE TABLE dup_countries postgres-# AS SELECT * postgres-# FROM countries; SELECT 0
Here is the command to see the structure of the created table :
postgres=# \d dup_countries
Table "public.dup_countries"
Column | Type | Modifiers
--------------+-----------------------+-----------
country_id | character varying(3) |
country_name | character varying(45) |
region_id | numeric(10,0) |
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous: Write a sql statement to create the structure of a table dup_countries similar to countries.
Next: Write a SQL statement to create a table countries, set a constraint NULL.
What is the difficulty level of this exercise?
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework