KatInterview

Design a University Enrollment Schema, Warehouse, and SQL

SQL & DataModel answer
HardModel answerSQL & Datadata-modelingstar-schemaSCD

Last updated

Model a university domain in 3NF, build a star schema with SCD Type 2 history, plan partitioning for 100M+ rows, and write two analytic queries.

University Enrollment: End-to-End Data Design

You are designing the data layer for a university registrar system. The domain has five entities: Students, Courses, Departments, Instructors, and Enrollments. Work through each part below and explain your reasoning as you go.


Part 1 — Transactional Schema (OLTP)

Design a normalized (3NF) relational schema for the entities above.

Your schema must enforce:

  • A student may not register for two sections of the same course in the same term.
  • A grade must be one of: A, B, C, D, F, Pass, Fail, Incomplete (or NULL while in progress).

For each table, specify primary keys, foreign keys, and any other constraints. Then list the indexes you would create and justify each one.


Part 2 — Analytical Warehouse (OLAP)

Design a star schema for enrollment analytics. At minimum, define a FactEnrollment table with measures like credits_attempted, credits_earned, and grade_points, plus dimension tables for Student, Course, Department, Term, and Instructor.

Address:

  • What grain did you choose and why?
  • Why use surrogate keys instead of natural keys?
  • Apply SCD Type 2 to DimStudent to track major changes over time. Show the required columns and explain how you guarantee point-in-time correctness when joining.

Part 3 — Physical Design at Scale

The FactEnrollment table has grown past 100 million rows. Propose a partitioning and clustering strategy. Justify your choices by referencing typical query access patterns and maintenance operations.


Part 4 — Write the SQL

Using whichever schema (OLTP or warehouse) is more natural for each query:

Query A. Return the full name of every student who enrolled in both CS101 and MATH201 during the same term.

Query B. For the most recently completed term, compute the top 3 departments by credit-weighted average GPA. Exclude Pass, Fail, and Incomplete grades from the GPA calculation. Break ties deterministically.


Part 5 — Design Trade-offs

In two to four sentences each:

  • How do the OLTP and OLAP designs differ in their priorities and trade-offs?
  • When would you prefer a snowflake schema over a flat star schema in this domain?

Hints

Hint 1

The 'no two sections of the same course in one term' constraint cannot be enforced with a simple UNIQUE on (student_id, section_id). Think about which columns you need to carry onto the enrollments table and how a composite foreign key locks in their correctness.

Hint 2

GPA is not the average of per-row GPA values. Store grade_points and gpa_credits as additive measures so you can compute SUM(grade_points) / SUM(gpa_credits) at any aggregation level. Pass/Fail grades need a gpa_credits value of 0.

Hint 3

Partition FactEnrollment by term, not by student or course. Almost every analytic query filters by term, and term-level partitions make ETL idempotent: you can overwrite a whole partition instead of merging individual rows.