Lesson 1.4 – Unit 1 Project – SchoolHub ERD and T-SQL Schema
SchoolHub ERD & T-SQL Schema
The unit comes together. Sketch the ERD, build the four-table SchoolHub schema in T-SQL with IDENTITY primary keys and foreign keys, populate it with real data, and prove it works with a four-table INNER JOIN.
Capstone Objectives
This lesson is the synthesis of Unit 1. By the end you will have:
- Designed and drawn an Entity-Relationship Diagram (ERD) for SchoolHub with four entities and the relationships between them.
- Built the SchoolHub schema in T-SQL with four tables,
IDENTITYprimary keys, and correct foreign key constraints. - Populated the database with enough sample data to support every later unit.
- Written a 4-table
INNER JOINquery that returns one combined row per student-class enrollment. - Submitted a working, normalized schema you can use as a portfolio piece and as the practice database for Units 2-10.
🏗️ What You're Building
This is the project that ties Unit 1 together: SchoolHub, a working four-table school database in SQL Server. Everything you've learned — flat vs. hierarchical vs. relational (Lesson 1.1), tables and keys (1.2), normalization to 3NF (1.3) — comes together here.
The deliverable is a single .sql file that, when run from top to bottom in the Knowledge Pillars Coding Lab, creates and populates the entire SchoolHub database from scratch. It should include:
- An ER diagram sketch (paper or digital — submit a photo or screenshot).
- Four
CREATE TABLEstatements with appropriate data types,IDENTITYPKs, andFOREIGN KEYconstraints. - At least 8 students, 4 teachers, 6 classes, and 15 enrollments.
- A 4-table
INNER JOINquery that demonstrates everything connects. - Comments throughout so a reviewer can follow your thinking.
📐 Step 1 — Sketch the ERD
Before writing a single line of T-SQL, sketch the ER diagram. ERDs are how database designers think on paper. They make the structure obvious before any syntax can get in the way.
The SchoolHub entities
You have four entities to model:
- Students — the people learning.
- Teachers — the people teaching.
- Classes — the courses offered.
- Enrollments — which student is in which class (the link).
The relationships
- A teacher can teach many classes, but each class has exactly one teacher. → One-to-many from Teachers to Classes.
- A student can be enrolled in many classes, and a class can have many students. → Many-to-many, resolved by the Enrollments junction table.
Your ERD should look something like this:
.sql file.
🛠️ Step 2 — Build the T-SQL Schema
Now translate the ERD into actual T-SQL. Open the Coding Lab and create lesson1_4.sql. Type out each CREATE TABLE statement carefully — don't copy-paste.
Table order matters
Because foreign keys point from child tables to parent tables, you must create the parents first. The build order is:
StudentsandTeachers(no foreign keys — pure parent tables).Classes(foreign key toTeachers).Enrollments(foreign keys to bothStudentsandClasses).
📥 Step 3 — Insert Sample Data
Add at least 8 students, 4 teachers, 6 classes, and 15 enrollments. Make the data plausible — give some students more classes than others, and assign each teacher to a couple of classes. You're free to use the data below or invent your own.
🔍 Step 4 — Prove It All Connects
The capstone test: a single query that joins all four tables and returns one row per enrollment with the student's name, the class name, the teacher's name, and the grade. If this works, your schema is correctly designed and populated.
⭐ Optional Stretch Goals
If you finish early and want to push your skills further, try one or more of these. They're not required for full credit, but they're great practice:
- Add a
DateOfBirthcolumn of typeDATEtoStudentsand populate it. Then write a query that returns student name and age. - Add a
Semestercolumn toClasses(e.g.,NVARCHAR(20)like'Fall 2024'). Populate it. Then write a query showing how many classes run each semester. - Add a
CHECKconstraint toStudents.GradeLevelso it only accepts values 9 through 12. Try inserting an invalid grade — what error does SQL Server give? - Build a query that lists each teacher and how many students they teach (use
COUNT(DISTINCT e.StudentID)). This is a preview of what's coming in Unit 3.
📦 Submission Instructions
To submit your Unit 1 capstone, include all three of the following:
- Your ERD sketch (PNG, PDF, or photo) showing all four tables and their relationships, with PK and FK labels.
- Your
.sqlfile, namedlesson1_4_(FirstName_LastName).sql. It must run cleanly from top to bottom in the Coding Lab. - A short reflection (3-5 sentences in a text file or at the bottom of your SQL file as a comment): What was easiest? What tripped you up? What would you do differently next time?
- Tables created in the wrong order, so FK constraints fail.
- Forgetting
NOT NULLon columns that need it. - Using
VARCHARinstead ofNVARCHARfor names (international students!). - Forgetting the composite PK on
Enrollments, allowing a student to be "enrolled" in the same class twice. - No comments in the SQL file — the script works but a reviewer can't tell what's going on.
📋 Grading Rubric (100 pts)
| Criterion | Excellent (full) | Proficient (partial) | Needs Work (low) | Pts |
|---|---|---|---|---|
| ERD Diagram | All 4 entities, all relationships, all PKs/FKs labeled clearly. | Missing 1 relationship or some labels. | Significant pieces missing. | 15 |
| Tables Built | All 4 tables with correct columns, types, IDENTITY PKs. |
Tables exist with minor type errors. | Missing tables or major type mistakes. | 25 |
| Constraints | All FKs declared; NOT NULL used appropriately; composite PK on Enrollments. |
Some FKs missing or composite PK omitted. | FK constraints largely absent. | 20 |
| Sample Data | 8+ students, 4+ teachers, 6+ classes, 15+ enrollments — all valid. | Met minimums but some data feels arbitrary. | Below minimum counts or invalid FK refs. | 15 |
| 4-Table JOIN | Query runs and returns correct combined rows ordered sensibly. | JOIN works but with minor issues (missing column, wrong order). | Query doesn't run or returns wrong data. | 15 |
| Code Quality | Comments throughout; consistent style; clear naming; GO separators. |
Some comments missing or inconsistent style. | No comments; messy formatting. | 10 |
✅ Self-Check Before Submitting
IDENTITY primary key (or composite PK for the junction).FOREIGN KEY ... REFERENCES.NVARCHAR with sensible lengths.INNER JOIN query runs and returns the expected combined data.🎤 Reflection Questions
Reflect on what you built — answer at least three:
- If your school wanted to add attendance tracking, what new table(s) would you add to SchoolHub? What would the keys look like?
- Which part of designing the schema was hardest — the ERD, the data types, or the foreign keys? Why?
- If you had to explain the difference between a one-to-many and many-to-many relationship to a friend in one sentence, what would you say?
- How does the composite primary key on
Enrollmentsprevent duplicate enrollments? What would happen without it? - What's one thing you'd change about the SchoolHub schema if you were designing it for a real school district?
➡️ What's Next
You've finished Unit 1 — the foundation. From here, every unit gets more interesting and more powerful because you have a real schema to work with.
Unit 2: Filtering, Patterns & Conditional Logic will teach you how to actually ask questions of SchoolHub. You'll write WHERE clauses to find specific students, use LIKE for pattern matching, and use CASE to categorize data.
Keep your lesson1_4.sql file safe — you'll re-run it at the start of every future unit to reset SchoolHub to a known state.
