w3resource

PostgreSQL Create Table: Create a table countries set a constraint NULL


5. Write a SQL statement to create a table countries, set a constraint NULL.

Sample Solution:

Code:

CREATE TABLE IF NOT EXISTS countries ( 
COUNTRY_ID varchar(2) NOT NULL,
COUNTRY_NAME varchar(40) NOT NULL,
REGION_ID decimal(10,0) NOT NULL
);

Output:

postgres=# CREATE TABLE IF NOT EXISTS countries (
postgres(# COUNTRY_ID varchar(2) NOT NULL,
postgres(# COUNTRY_NAME varchar(40) NOT NULL,
postgres(# REGION_ID decimal(10,0) NOT NULL
postgres(# );
CREATE TABLE

Here is the command to see the structure of the table, just created :

postgres=# \d countries;
           Table "public.countries"
    Column    |         Type          | Modifiers
--------------+-----------------------+-----------
 country_id   | character varying(2)  | not null
 country_name | character varying(40) | not null
 region_id    | numeric(10,0)         | not null

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a SQL statement to create a duplicate copy of countries table, including structure and data by name dup_countries.
Next: Write a SQL statement to create a table named jobs, including job_id, job_title, min_salary, max_salary and check whether the max_salary amount exceeding the upper limit 25000.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming