Episode #15 | Inserting Data Into Our Database


Wednesday, 31 Oct 2018 Kudzai Nyandoro 5:31 Minutes

Description:

In this episode, we're going to learn how to insert data into our database using SQL's INSERT command.

Notes:

$ psql rivers

Add the first river name and ideal flow.

INSERT INTO california_rivers(name, ideal_flow)
VALUES('Kings', 2500);

Add the second river name and ideal flow.

INSERT INTO california_rivers(name, ideal_flow)
VALUES('San Joaquin', 1500);

Add the third river name and ideal flow.

-- Insert California Rivers data

INSERT INTO california_rivers(name, ideal_flow)
VALUES('Merced', 600);

Add the fourth river name and ideal flow.

INSERT INTO california_rivers(name, ideal_flow)
VALUES('Kern', 1500);

Use the SQL SELECT query to view the inserted data

rivers=# SELECT * FROM california_rivers;

Viewing all inserted data

river_id |    name     | ideal_flow 
----------+-------------+------------
        1 | Kings       |       2500
        2 | Kern        |       1500
        3 | San Joaquin |       1500
        4 | Merced      |        600
(4 rows)

Exit from the PostgreSQL console

rivers=# \q