The Fee Tracker Database
Every example in this course runs on one small database: the Fee Tracker. It holds the records of a family-run tutoring program where three sisters, Srihitha, Advitha and Navika Anamaneni, take courses in Java, SQL, JavaScript and Git. Knowing it well pays off: when a later lesson says "the students with no payments," you'll already know who that is. This lesson tours its five tables, explains every column, shows how the tables connect, and points out the special cases that later lessons rely on.
In One Minute
- The Fee Tracker has five tables:
students,courses,enrollments,paymentsand a small lookup table,cities. - Enrollments connect students to courses; payments belong to an enrollment, and one enrollment can have several payments (installments).
- It's small on purpose (3 students, 6 courses, 7 enrollments, 7 payments), so you can see every row and check every answer by eye.
- A few special cases are built in on purpose: a student with no payments, a course nobody takes, a payment with no method, two late payments.
- Every Try it run starts from a fresh copy, and locally you reset it by loading
fee-tracker.sqlagain.
The Five Tables at a Glance
Here is the whole database in one picture: every table, every column and every connection. The marks at the ends of the lines say how many rows can match on each side, as you learned in What Is a Database.
| Table | One row is | Rows |
|---|---|---|
students | One student | 3 |
courses | One course the program offers | 6 |
enrollments | One student taking one course | 7 |
payments | One fee payment | 7 |
cities | One city where students live, with its time zone | 2 |
Students
The students table has one row per student. Run it to see every column:
SELECT *
FROM students
ORDER BY student_id; student_id | first_name | last_name | email | phone | city | state | grade | mentor_id | joined_on
------------+------------+-----------+--------------------------------+----------------+---------------+-------+-------+-----------+------------
101 | Srihitha | Anamaneni | srihitha.anamaneni@example.com | (415) 555-0142 | San Francisco | CA | 12 | NULL | 2024-08-19
102 | Advitha | Anamaneni | NULL | (415) 555-0178 | San Francisco | CA | 10 | 101 | 2025-01-13
103 | Navika | Anamaneni | NULL | NULL | Dallas | TX | 7 | 102 | 2025-09-02
(3 rows)| Column | Meaning |
|---|---|
student_id | The primary key: a number that identifies the student |
first_name, last_name | The student's name |
email, phone | Contact details; either can be NULL when it's not on file |
city, state | Where the student lives; together they match a row in cities |
grade | School grade, from 1 to 12 |
mentor_id | The student_id of the student who mentors this one, or NULL for no mentor |
joined_on | The date the student joined the program |
Srihitha is the eldest and mentors Advitha; Advitha mentors Navika. Srihitha and Advitha live in San Francisco, and Navika lives in Dallas.
Courses
The courses table has one row per course.
SELECT *
FROM courses
ORDER BY course_id; course_id | title | technology | level | fee_usd | prerequisite_id
-----------+-------------------+------------+--------------+---------+-----------------
1 | Java Basics | Java | Beginner | 450.00 | NULL
2 | Java OOP | Java | Intermediate | 500.00 | 1
3 | Java Collections | Java | Intermediate | 550.00 | 2
4 | SQL Basics | SQL | Beginner | 400.00 | NULL
5 | JavaScript Basics | JavaScript | Beginner | 450.00 | NULL
6 | Git Basics | Git | Beginner | 250.00 | NULL
(6 rows)| Column | Meaning |
|---|---|
course_id | The primary key |
title | The course name; no two courses share one |
technology | Java, SQL, JavaScript or Git |
level | Beginner or Intermediate |
fee_usd | The current fee in US dollars, with exactly two decimal places |
prerequisite_id | The course_id of the course you must finish first, or NULL if there isn't one |
The prerequisites form a chain: Java Basics, then Java OOP, then Java Collections.
Enrollments
The enrollments table has one row for each student taking a course. This table is what connects students to courses: a student can take many courses, and a course can have many students.
SELECT *
FROM enrollments
ORDER BY student_id, course_id; student_id | course_id | enrolled_on | status
------------+-----------+-------------+-----------
101 | 1 | 2025-08-25 | completed
101 | 2 | 2025-10-27 | completed
101 | 3 | 2025-12-22 | active
101 | 4 | 2026-01-02 | active
102 | 1 | 2025-12-29 | active
102 | 4 | 2025-12-29 | active
103 | 5 | 2025-11-10 | active
(7 rows)| Column | Meaning |
|---|---|
student_id | Who is enrolled; matches a row in students |
course_id | Which course; matches a row in courses |
enrolled_on | The date they signed up |
status | active, completed or dropped |
An enrollment has no id of its own: the pair student_id and course_id is its primary key, so the same student can't enroll in the same course twice.
Payments
The payments table has one row per payment.
SELECT *
FROM payments
ORDER BY payment_id; payment_id | student_id | course_id | amount_usd | due_on | paid_on | method
------------+------------+-----------+------------+------------+------------+--------
1 | 101 | 1 | 450.00 | 2025-09-01 | 2025-08-28 | card
2 | 101 | 2 | 250.00 | 2025-11-01 | 2025-10-30 | card
3 | 101 | 2 | 250.00 | 2025-12-01 | 2025-12-03 | check
4 | 101 | 3 | 550.00 | 2026-01-02 | 2025-12-29 | card
5 | 101 | 4 | 200.00 | 2026-01-05 | 2026-01-05 | NULL
6 | 103 | 5 | 225.00 | 2025-11-15 | 2025-11-14 | card
7 | 103 | 5 | 225.00 | 2025-12-15 | 2025-12-19 | check
(7 rows)| Column | Meaning |
|---|---|
payment_id | The primary key |
student_id, course_id | The enrollment this payment belongs to. The pair must match a row in enrollments, so nobody can pay for a course they never enrolled in |
amount_usd | The amount actually paid, always more than zero |
due_on | The date the payment was due |
paid_on | The date it was paid |
method | card, check or cash, or NULL if nobody recorded it |
One enrollment can have several payments: Srihitha paid for Java OOP in two installments (payments 2 and 3), and so did Navika for JavaScript Basics (payments 6 and 7).
Cities
The cities table is a small lookup table: one row per city, with its time zone.
SELECT *
FROM cities
ORDER BY state; city | state | time_zone
---------------+-------+---------------------
San Francisco | CA | America/Los_Angeles
Dallas | TX | America/Chicago
(2 rows)Its primary key is the pair city and state, because two states can have a city with the same name. Every student's city and state must match a row here. The time zones matter when a later lesson sends reminders at the right local time: Dallas is on Central time and San Francisco on Pacific time.
How the Tables Connect
Every connection is a foreign key: a column (or a pair of columns) whose values must match a key in another table. These are all of them, read from the database itself:
| Child column | Must match | In plain English |
|---|---|---|
students.(city, state) | cities.(city, state) | Every student lives in a known city |
students.mentor_id | students.student_id | A mentor is another student (or NULL) |
enrollments.student_id | students.student_id | Every enrollment is for a real student |
enrollments.course_id | courses.course_id | Every enrollment is for a real course |
courses.prerequisite_id | courses.course_id | A prerequisite is another course (or NULL) |
payments.(student_id, course_id) | enrollments.(student_id, course_id) | Every payment belongs to an enrollment |
payments.student_id | students.student_id | Also checked on its own |
payments.course_id | courses.course_id | Also checked on its own |
Here is what that looks like with real rows. Start from one payment and follow the matching values into every other table:
Deliberate Special Cases
A sample database where everything is neat teaches you very little. Real data has gaps, and many SQL features exist to handle them. The Fee Tracker includes a few on purpose, and later lessons come back to each one:
| Special case | Why it's there |
|---|---|
| Advitha has no payments | Finding rows with no match (LEFT JOIN, NOT EXISTS) |
| Git Basics has no enrollments | The same idea from the course side (FULL JOIN) |
| Advitha and Navika have no email; Navika has no phone | Handling NULL (COALESCE, IS NULL) |
| Payment 5 has no method | NULL in a column you group by |
| Payments 3 and 7 were paid after their due date | Comparing dates and labeling late payments (CASE) |
| Two payments of $250.00 and two of $225.00 | Ties when ranking (RANK and DENSE_RANK) |
You can see the late payments already, with a WHERE that compares two date columns:
SELECT payment_id, due_on, paid_on
FROM payments
WHERE paid_on > due_on
ORDER BY payment_id; payment_id | due_on | paid_on
------------+------------+------------
3 | 2025-12-01 | 2025-12-03
7 | 2025-12-15 | 2025-12-19
(2 rows)Resetting the Data
In Try it, there's nothing to reset. Every run starts from a fresh copy of the Fee Tracker, so you can insert, change and delete rows freely; the next run brings everything back.
On your own PostgreSQL, changes stay until you undo them. To start over, drop the database and load the script again, as in Setting Up SQL. Connect to postgres first, because PostgreSQL won't drop the database you're connected to:
feetracker=# \c postgres
postgres=# DROP DATABASE feetracker;
postgres=# CREATE DATABASE feetracker;
postgres=# \c feetracker
feetracker=# \i /Users/you/Downloads/fee-tracker.sqlCommon Mistakes
Expecting an enrollment_id. Enrollments are identified by the pair student_id and course_id. Payments use the same pair to point at their enrollment.
Confusing fee_usd and amount_usd. courses.fee_usd is the current price of a course; payments.amount_usd is what one payment actually was. A course fee of $500.00 can be paid as two payments of $250.00.
Assuming every student has a payment, or every course has a student. Advitha has none, and Git Basics has none. Queries that join tables have to decide what to do with them.
Practice
Challenge: Who still has an active enrollment? List the student_id and course_id of every enrollment whose status is active, sorted by student_id and then course_id. How many are there?
Show solution
SELECT student_id, course_id
FROM enrollments
WHERE status = 'active'
ORDER BY student_id, course_id; student_id | course_id
------------+-----------
101 | 3
101 | 4
102 | 1
102 | 4
103 | 5
(5 rows)Five enrollments are active. Srihitha's first two courses are completed, so they don't appear.
Key Takeaways
| You want to | Look in |
|---|---|
| A student's name, contact details or mentor | students |
| A course's fee or prerequisite | courses |
| Who takes which course | enrollments |
| Who paid what, and when | payments |
| A city's time zone | cities |
Was this tutorial helpful?