This repository contains a simple multi-purpose data set for PostgreSQL database. Feel free to reuse it to bootstrap your projects.
This data set is composed of two tables:
planet
: List of planets appearing in Star Wars movies (61 records)people
: List of people appearing in Star Wars movies (87 records)
There is a relationship between planets and people as one planet is the homeworld of one or several persons. It is a "one-to-many" relationship (one planet, many people). The planet_id
column in the people
table is a foreign key of the planet
table.
- Connect to your PostgreSQL database server with the client of your choice
- Copy SQL statements from the file database.sql
- Execute SQL statements, they will do the following:
- Create a new database named
star_wars
- Create a new schema named
base
- Create
planet
andpeople
tables - Insert data into both tables
- Create a new database named
Count number of planets:
\connect star_wars;
select count(*) from base.planet;
count
-------
61
(1 row)
Find the Skywalker family:
\connect star_wars;
select a.name as character, b.name as planet
from base.people a
inner join base.planet b on a.planet_id=b.id
where a.name like '%Skywalker%';
character | planet
------------------+----------
Shmi Skywalker | Tatooine
Anakin Skywalker | Tatooine
Luke Skywalker | Tatooine
(3 rows)
Star Wars and all associated names are copyrighted by Lucasfilm ltd.
All data has been collected from the open source website Star Wars API.