Knowledge / Computer Science and Engineering / Database design case studies

Database design case studies

Computer Science and Engineering (B.E./B.Tech) · Databases · free study notes for exams, placements and interviews

In short

A database design case study takes a real business statement, turns it into entities, relationships and constraints, normalises them, and then settles the physical choices - keys, indexes, data types, partitions and audit columns - that make the schema work at the required load. It is the applied end of database theory: the same requirement handled badly produces redundancy, update anomalies, wrong reports and slow queries. Indian university syllabi set it as a mini-project plus a 10 to 15 mark design question (library, railway reservation, hospital, payroll, university, banking), and GATE tests the reasoning fragments - key identification, dependency-preserving decomposition, constraint choice. In placement rounds at TCS, Infosys, Wipro, Cognizant, Accenture, Zoho, Freshworks, Paytm and Zoho-style product firms, "design the schema for X" is a standard 20-minute whiteboard question.

Explained

The design lifecycle - six stages

  1. Requirement analysis: collect nouns (candidate entities), verbs (candidate relationships), reports needed, volumes, growth rate, retention period and who may see what. Output: a written requirement list with volumes.
  2. Conceptual design: an ER / EER diagram - entity sets, attributes, cardinality (1:1, 1:N, M:N), participation (total/partial), weak entities, specialisation/generalisation. Independent of any DBMS.
  3. Logical design: map ER to relations, choose primary and foreign keys, normalise to 3NF/BCNF, state constraints (NOT NULL, UNIQUE, CHECK, referential actions).
  4. Physical design: data types and widths, clustering, indexes, partitioning, fill factor, tablespaces, storage engine (InnoDB vs MyISAM), collation.
  5. Implementation and population: DDL scripts, reference/master data seeding, views, stored procedures, roles and grants.
  6. Tuning and evolution: measure actual queries, add or drop indexes, denormalise selectively, version the schema with migration scripts.

ER-to-relational mapping rules used in every case study

Design decisions that recur, and how to settle them

Normalisation in practice, and controlled denormalisation

Case study 1 - Library management system

Case study 2 - Railway reservation (IRCTC-style)

Case study 3 - Hospital management system

Case study 4 - Payroll, university and e-commerce in brief

Evaluating a design

Key points

Formulas and examples

Maximum relationships in an ER diagram with n entity sets (binary, unordered, one per pair): n(n−1)/2
Number of tables for a binary relationship: 1:1 → 1 or 2; 1:N → 2; M:N → 3
Number of tables for specialisation with k subclasses: single-table = 1; superclass + subclass tables = k+1; concrete-class tables only = k
Rows in a junction table ≤ |A| × |B| (full cross-participation is the upper bound)
Table size ≈ rows × (sum of column widths + row overhead); index size ≈ rows × (key width + pointer)
Storage growth per year = rows per day × 365 × bytes per row
Selectivity = matching rows / total rows; an index helps most when selectivity is below roughly 5 to 10%

Example 1 - ER to tables, library. Entities BOOK, BOOK_COPY, MEMBER, AUTHOR; relationships BOOK 1:N BOOK_COPY, BOOK M:N AUTHOR, MEMBER 1:N ISSUE, BOOK_COPY 1:N ISSUE.

-- PostgreSQL dialect throughout (MySQL: INT AUTO_INCREMENT for the ids,
-- and no filtered index, so use a current_issue table in place of ux_open_issue)
CREATE TABLE book (
  book_id      INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  isbn         CHAR(13) UNIQUE,
  title        VARCHAR(200) NOT NULL,
  publisher_id INT REFERENCES publisher(publisher_id)
);
CREATE TABLE book_copy (
  copy_id   INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  book_id   INT NOT NULL REFERENCES book(book_id),
  accession VARCHAR(20) UNIQUE NOT NULL,
  status    VARCHAR(10) NOT NULL CHECK (status IN ('ON_SHELF','ISSUED','LOST','REPAIR'))
);
CREATE TABLE issue (
  issue_id    INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
  copy_id     INT NOT NULL REFERENCES book_copy(copy_id),
  member_id   INT NOT NULL REFERENCES member(member_id),
  issue_date  DATE NOT NULL,
  due_date    DATE NOT NULL,
  return_date DATE,
  CHECK (due_date >= issue_date)
);
CREATE UNIQUE INDEX ux_open_issue ON issue(copy_id) WHERE return_date IS NULL;

Example 2 - fine computation and policy table. Policy: 14 days free, ₹2 per day after that, cap ₹200. A member returns on day 61.

Example 3 - storage estimate, railway seat inventory. 13,000 trains, average 18 coaches, average 70 berths = 13,000 × 18 × 70 ≈ 16.38 million berth rows per journey date. Booking window 60 days.

Example 4 - normalising a flat sheet (payroll). Flat table: (emp_id, emp_name, dept_name, month, basic, hra, pf, net), key (emp_id, month).

Example 5 - comparison of specialisation strategies for PERSON → STUDENT, FACULTY, STAFF (10,000 students, 600 faculty, 400 staff):

StrategyTablesQuery all personsQuery one subtypeNullsVerdict
Single table + type column1TrivialFilter on typeManyGood when subtypes are thin and queried together
Superclass + subclass tables4Join or UNIONJoin 2 tablesNoneStandard 3NF answer; used in university ERPs
One table per concrete class3UNION of 3DirectNoneFast per subtype, no shared identity - avoid if a person can be two subtypes
Design questionOLTP choiceReporting choice
Normal form3NF / BCNFStar schema (dimensions denormalised)
KeysSurrogate + unique naturalSurrogate dimension keys, date key
IndexesNarrow, selective, on predicatesFew; columnar or bitmap-style storage
WritesMany short transactionsBulk load / nightly ETL
TotalsComputed or cached with a rebuildPre-aggregated measures

Where it is used

Interview questions

Common mistakes

Related topics

ER model and normalisation · SQL queries and joins · Transactions, ACID and indexing · Query processing and optimisation · NoSQL databases · Software engineering: requirement analysis and SRS

Open in the Knowledge reader →Find jobs →