PostgreSQL Create Table: Create a table countries, with columns country_id, country_name and region_id
1. Write a SQL statement to create a simple table countries, including columns country_id, country_name and region_id.
Sample Solution:
Code:
CREATE TABLE countries (
COUNTRY_ID varchar(3),
COUNTRY_NAME varchar(45) ,
REGION_ID decimal(10,0)
);
Output:
postgres=# CREATE TABLE countries ( postgres(# COUNTRY_ID varchar(3), postgres(# COUNTRY_NAME varchar(45), postgres(# REGION_ID decimal(10,0) postgres(# ); CREATE TABLE
To see the structure of the created table :
postgres=# postgres=# \d countries;
Table "public.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.
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