CASE STUDY 01 · RELATIONAL DESIGN

Academic Operations 3NF + Reporting

College Management Database

Convert student registration, course enrollment, marks and attendance into a normalized database whose rules are enforced even when an application makes a mistake.

01 · PROBLEM & SCOPE

One academic truth, many useful views

A college must store students, their departments, offered courses, semesters, enrollments, marks and attendance. Faculty need course lists, students need transcripts, and coordinators need shortage and performance reports. Spreadsheets copy department and course names into many rows, so a spelling change creates conflicting versions.

Actors

Student, faculty member, department coordinator and administrator.

Core event

A student enrolls in one course during one semester.

Boundary

This teaching scope excludes fees, timetabling and authentication.

Integrity objective: invalid marks, orphan enrollments and duplicate registrations must be rejected by the database—not merely hidden by the interface.
02 · REQUIREMENTS & RULES

Translate sentences into constraints

RuleDatabase mechanismFailure prevented
Roll number and email identify one studentUNIQUEDuplicate identity
Every student belongs to an existing departmentFOREIGN KEYOrphan student
Credits are 1–6; marks and attendance are 0–100CHECKImpossible academic values
One registration per student/course/semesterComposite PRIMARY KEYDouble enrollment
Deleting a student removes their enrollmentsON DELETE CASCADEDangling dependent rows

Marks may be NULL until evaluation, which differs from zero marks. Attendance defaults to zero only because the teaching workflow creates a record before sessions are counted. A production system should also record who changed marks and when.

03 · CONCEPTUAL & LOGICAL MODEL

Enrollment resolves a many-to-many relationship

Department
1 → N
Student
1 → N
Enrollment
N ← 1
Course

A student takes many courses and a course has many students. enrollment becomes an associative entity and carries relationship facts: semester, marks and attendance. Putting marks inside student would require repeating columns; putting a comma-separated student list inside course would violate atomicity and make joins unreliable.

Keys

  • Surrogate integer keys keep joins compact.
  • Natural identifiers—roll number, course code and email—remain unique candidate keys.
  • The enrollment composite key represents its real identity and blocks duplicates without application code.
04 · NORMALIZATION WALKTHROUGH

Move each fact to the table it describes

An unnormalized row such as (roll_no, student_name, department_name, course1, marks1, course2, marks2) has repeating groups. First normal form creates one course registration per row. Second normal form removes attributes depending on only part of the registration key: student name belongs to student and course title belongs to course. Third normal form removes transitive facts: department head depends on department, not on student.

Update anomaly removed

A changed HOD is updated once in department.

Insertion anomaly removed

A course may exist before any student enrolls.

Deletion anomaly removed

Removing the last enrollment does not erase the course definition.

Trade-off

Reports need joins; correctness is worth that explicit work.

05 · REPORT DESIGN

Ask questions at the correct grain

The transcript query begins at enrollment because one output row represents one registered course. Course performance groups by course and uses conditional aggregation for pass percentage. Attendance shortage filters individual enrollment facts before ordering.

weighted average = Σ(marks × credits) / Σ(credits)

The result view groups by student and semester. Every selected non-aggregate is functionally determined by those grouping keys. NULL marks should be handled according to published academic policy; silently converting “not evaluated” to zero can misrepresent performance.

06 · COMPLETE IMPLEMENTATION

Executable SQLite schema, seed data and reports

programs/college-management.sql
Loading source…

Run with sqlite3 :memory: < college-management.sql. The script activates foreign keys explicitly, creates constraints and indexes, inserts deterministic sample data, builds a view and executes four reports.

07 · INTERACTIVE EXECUTION TRACE

Follow one enrollment from rule to report

  1. Open transaction.
  2. Create referenced facts.
  3. Check relationships.
  4. Prevent duplication.
  5. Validate values.
  6. Publish transaction.
  7. Build readable report.
  8. Aggregate outcomes.
Current state

Press Next to begin.

08 · TEST STRATEGY

Try to break the rules deliberately

Happy path
Insert a valid enrollment and confirm it appears once in transcript and aggregate reports.
Duplicate registration
Repeat the same student/course/semester tuple; expect a primary-key failure.
Orphan reference
Use a nonexistent course ID; expect a foreign-key failure while foreign keys are enabled.
Boundary values
Accept marks 0 and 100; reject −1 and 101. Repeat for attendance and credits.
Null semantics
Insert an unevaluated mark as NULL and verify the report policy does not confuse it with zero.
Cascade scope
Delete a test student and verify only that student’s enrollments disappear; course and semester remain.
09 · INDEX & TRANSACTION REASONING

Index access paths, not every column

Primary and unique keys already create lookup structures. idx_student_department supports department rosters; idx_enrollment_course_sem supports course lists within a semester. Every index consumes storage and adds work to inserts and updates, so justify it with frequent filters, joins or orderings and verify with EXPLAIN QUERY PLAN.

Multi-table registration should run in one transaction. Concurrent systems also need isolation decisions: preventing two coordinators from overwriting marks may require optimistic version columns or database-specific locking. Backups, role-based permissions, encryption and an immutable audit log belong in production.

10 · PRACTICE & EXTENSIONS

Check design judgment

Where should marks be stored?

What prevents the same course registration twice?

Build further

  1. Add faculty and course-offering tables so one course can have different teachers each semester.
  2. Add grade rules without hard-coding one policy into old results.
  3. Create department rank and attendance-shortage reports with window functions.
  4. Add an append-only marks audit table and authorization model.
  5. Compare query plans before and after a purposeful composite index.
11 · INTERVIEW PREPARATION

Defend the model

Why not store course IDs as comma-separated text?

It violates atomicity, prevents foreign-key enforcement, complicates searching and makes updates error-prone.

Primary key versus unique key?

A table has one primary key identifying rows; it may have multiple additional unique candidate keys. Primary-key columns are non-null.

Why can a foreign key still fail in SQLite?

Foreign-key enforcement must be enabled per connection with PRAGMA foreign_keys=ON.

What is the report grain?

It is what one result row represents. Declaring grain before grouping prevents double counting.

When denormalize?

Only after measured performance evidence, with a clear refresh/consistency strategy; normalization remains the source of truth.

12 · KEY TAKEAWAY

A database is an integrity system, not a collection of tables

The design succeeds because each fact has one home, relationships are explicit, invalid states are constrained, reports respect their grain, and indexes answer demonstrated access needs. Application validation improves experience; database constraints protect every application.