Student starter code (30% baseline)
index.html- Main HTML pagescript.js- JavaScript logicstyles.css- Styling and layoutpackage.json- Dependenciessetup.sh- Setup scriptREADME.md- Instructions (below)๐ก Download the ZIP, extract it, and follow the instructions below to get started!
Welcome to your first database activity! This template helps you learn the fundamentals of databases, SQL queries, and data management using a realistic contact manager system.
By completing this activity, you will:
IMPORTANT: This template includes WORKING CODE! You can see results immediately:
Download SQLite Browser (if you don't have it):
Open the database files:
contacts.dbsqlite/schema.sql -> Click "Execute" โถ๏ธsample-data.sql -> Click "Execute" โถ๏ธRun the queries:
sqlite/queries.sql# Make sure you're in the activity folder, then:
docker-compose up -d
# Access MySQL:
docker exec -it w4-mysql mysql -u root -plearning123 contacts_db
# Access PostgreSQL:
docker exec -it w4-postgres psql -U postgres contacts_db
70% of the code is implemented for you:
Location: sqlite/queries.sql line 132
Your Task: Write a query to find contacts that have BOTH email AND phone
Success Criteria:
Hints:
WHERE with AND operatoremail IS NOT NULLfirst_name || ' ' || last_name AS full_nameWhy This Matters: In real applications, you need contacts with complete information for effective communication.
Location: sqlite/queries.sql line 154
Your Task: Find companies where you have 2+ contacts
Success Criteria:
Hints:
GROUP BY companyHAVING to filter groups: HAVING COUNT(*) >= 2HAVING is like WHERE but for grouped dataWhy This Matters: Identifying multiple contacts at the same organization helps with networking and relationship management.
Location: sqlite/queries.sql line 174
Your Task: Create a comprehensive contact statistics query
Success Criteria:
COUNT(), ROUND()Hints:
SELECT without FROM for calculationsROUND((count_subset * 100.0) / count_total, 1)100.0 instead of 100 for accurate divisionExpected Output: Single row like:
total_contacts | email_percentage | favorite_percentage
20 | 90.0 | 50.0
Why This Matters: Data analysis helps you understand your network health and prioritize relationship building.
| Field | Type | Purpose | Example |
|---|---|---|---|
id |
INTEGER | Unique identifier | 1, 2, 3... |
first_name |
TEXT | First name (required) | "Alice" |
last_name |
TEXT | Last name (required) | "Chen" |
email |
TEXT | Email address (unique) | "alice@google.com" |
phone |
TEXT | Phone number | "+1-555-0201" |
company |
TEXT | Organization | "Google" |
job_title |
TEXT | Position | "Senior Engineer" |
category |
TEXT | Relationship type | "Work", "Family", "Friend" |
favorite |
BOOLEAN | Starred contact | 0 or 1 |
last_contacted |
DATE | Last interaction | "2024-01-28" |
notes |
TEXT | Additional info | "Team lead, expert..." |
linkedin_url |
TEXT | LinkedIn profile | "https://linkedin.com/in/..." |
created_at |
DATETIME | Record creation | Auto-generated |
updated_at |
DATETIME | Last modification | Auto-updates |
-- View data
SELECT column1, column2 FROM table WHERE condition;
-- Filter results
WHERE category = 'Work'
WHERE email IS NOT NULL
-- Sort results
ORDER BY company, last_name;
-- Group and count
GROUP BY category
HAVING COUNT(*) >= 2
-- Combine columns
first_name || ' ' || last_name AS full_name
"No such table" error:
schema.sql first"No such column" error:
.schema contacts to see all columnsQuery returns 0 rows:
SELECT COUNT(*) FROM contacts;Syntax error:
| Query | Expected Count/Output |
|---|---|
| Query 1 | 20 rows (all contacts) |
| Query 2 | 10 rows (favorites) |
| Query 3 | 8 rows (work contacts) |
| Query 4 | 3 rows (Google employees) |
| Query 5 | Varies (contacts with 'e' in name) |
| Query 6 | 20 rows with follow-up status |
| Query 7 | 4 rows (category summary) |
| TODO 8 | 15-17 rows |
| TODO 9 | 2-3 rows |
| TODO 10 | 1 row with stats |
Ready for more? Try these bonus features:
Your project is complete when:
Once you complete this activity, you'll have:
This foundation will serve you well in the next activities where we'll explore multi-table relationships, advanced queries, and building full applications with databases!
Need Help?
Ready to Submit? Complete this activity and submit through the Activity Submission Form
Happy querying! ๐๏ธโจ