Introduction to databases and persistence
The Relational Model
SQL Basics, DDL, and DML
Querying Data
Advanced Concepts
Sqlite
Glossary of Database Terms
Practice
Assignment
Core program
Content
Exercise 1: The Todo List (Warmup)
Goal: Practice creating a single table and doing basic CRUD (Create, Read, Update, Delete) operations.
- Create a file
todo.db using sqlite3.
- Create a table named
todos with:
id (Integer, Primary Key)
task (Text, Not Null)
priority (Integer, Default 1)
completed (Boolean/Integer, Default 0)
- Insert 3 tasks: "Buy Milk", "Wash Car" (High Priority), "Learn SQL".
- Select all tasks.
- Update "Buy Milk" to be completed.
- Delete "Wash Car".
Exercise 2: The School (Relations & Joins)
Goal: Work with Foreign Keys and Joins.
-
Create the 3 tables: students, classes, enrollments (refer to Module 3 for the schema).
-
Insert:
- 3 Students (Harry, Hermione, Ron)
- 2 Classes (Potions, Transfiguration)
-
Enroll:
- Harry in Potions and Transfiguration.
- Hermione in Potions and Transfiguration.
- Ron in Potions.
-
Query 1: List all students in "Potions".
-
Query 2: List all classes that "Harry" is taking.
-
Query 3: Count how many students are in each class.
Exercise 3: Design Challenge - The Recipe App
Goal: Design a schema from scratch for a real-world problem.
Scenario:
You are building a recipe website.
- A Recipe has a name, description, and instructions.
- An Ingredient has a name (e.g., "Egg", "Flour").
- A Recipe needs many Ingredients.
- An Ingredient can be used in many Recipes.
- Crucial: When listing an ingredient for a recipe, you need the Quantity and Unit (e.g., "2 Eggs", "500g Flour").
Task:
- Design the tables on paper or a text file. (Hint: You need a Join Table!).
- Write the
CREATE TABLE statements.
- Insert "Pancakes":
- Ingredients: 1 Cup Flour, 2 Eggs, 1 Cup Milk.
- Write a query to get the full shopping list for "Pancakes".
Helpful Resources
The HackYourFuture curriculum is licensed under CC BY-NC-SA 4.0

*https://hackyourfuture.net/*
Found a mistake or have a suggestion? Let us know in the feedback form.