Skip to content

Latest commit

 

History

History
63 lines (41 loc) · 1.73 KB

File metadata and controls

63 lines (41 loc) · 1.73 KB

Setup

You need a local PostgreSQL server and the psql command-line client. If you've been following the Up and Running with SQL course, you already have this.

1. Verify PostgreSQL is installed

psql --version

You should see something like psql (PostgreSQL) 16.x. If not, install PostgreSQL first — the course covers this for macOS, Windows, and Linux.

2. Connect to your server

psql -U postgres

You should land in a prompt that looks like postgres=#.

3. Create a practice database

From the psql prompt:

CREATE DATABASE sql_exercise;

Then connect to it:

\c sql_exercise

Your prompt should now say sql_exercise=#. This is where you'll run all the exercises.

4. Loading a section's schema and seed data (when provided)

Some sections include a schema.sql (the tables) and a seed.sql (sample rows). To load them, from your terminal (not inside psql):

psql -U postgres -d sql_exercise -f 01-up-and-running-with-sql/02-working-with-tables/schema.sql

Each section's exercises.md tells you which files to load.

5. Resetting a section

If you break something and want a clean slate, just re-run the schema.sql for that section — every schema file starts with DROP SCHEMA IF EXISTS ... CASCADE; so it's safe to re-run.

6. Useful psql commands

Command What it does
\l List all databases
\c db_name Connect to another database
\dn List schemas in current database
\dt schema.* List tables in a schema
\d table_name Describe a table
\q Quit psql
\? Show all psql commands

You're ready. Start with 01-up-and-running-with-sql/.