In this tutorial, we're going to learn how to create a table using SQL and PostgreSQL.
Creating a Table
To create a table, first, start your PostgreSQL server by running one of the commands below, depending on the machine you're using.
If you're on AWS Cloud9: Start your PostgreSQL server if you've not yet started it.
$ sudo service postgresql start
If you're on a MacOS: Start your PostgreSQL server if you've not yet started it.
$ brew services start postgresql
If you're on an Ubuntu OS: Start your PostgreSQL server if you've not yet started it.
$ service postgresql start
Enter into the PostgreSQL database
$ psql postgres
View a list of all your databases
Connect to the rivers database
$ postgres=# \c rivers
Create a table for California Rivers
-- Create a table for California rivers CREATE TABLE california_rivers( river_id SERIAL PRIMARY KEY, name VARCHAR(50), ideal_flow INTEGER );
Our First SQL Query
rivers=# SELECT * FROM california_rivers; river_id | name | ideal_flow ----------+------+-------+---------+--------+----------+ (0 rows)