Robbo CRM
Databases course project · Oracle · relational model

Robbo CRM

A relational Oracle database for a club that teaches children robotics, programming, 3D modelling and electronics. It covers the whole life of a family: the first call, the trial lesson, weekly groups and attendance, summer camps, prepaid packages, invoices and payments. It is built from the structure of the club's real CRM export and loaded with an anonymised copy of its data.

01 · Domain

What the database models

A child enters as a lead when a parent calls or fills in a form. Every call is logged until the family books a trial lesson; after it the child can become a client, join a weekly group and buy a package of lessons. Each lesson records who came, and each attended lesson is charged from the package. Packages and camps are invoiced, and invoices are settled by payments.

02 · Entity-relationship diagram

28 tables, 45 relationships

Crow's-foot notation: lookup tables and BRANCH on the left, CUSTOMER and LESSON as the hubs, and the tables with the most parents (ATTENDANCE, INVOICE, PAYMENT) on the right. Scroll the diagram sideways, or open the interactive version to highlight one table's relationships.

Entity-relationship diagram of the Robbo CRM database with 28 tables and 45 one-to-many relationships
Every relationship is one-to-many; many-to-many links are resolved by associative tables. Interactive · SVG · PNG
03 · Schema

Tables, columns and constraints

Every column, key and named constraint exactly as created by 01_create_tables.sql, with the number of sample rows and the first rows of the anonymised data.

04 · Design decisions

Normalisation and integrity

The CRM export keeps most data in a few wide tables with lists and free text in single fields. The schema brings it to third normal form, and the rules that a CHECK cannot express are enforced by triggers.

1NF · atomic values

  • Comma-separated phone numbers → one row each in PARENT_PHONE.
  • Lists of teachers and students inside each lesson → LESSON_TEACHER, ATTENDANCE.
  • A free-text call history → one row per contact in CONTACT_LOG.

2NF · whole-key dependency

  • Associative tables keep only what depends on the whole key, e.g. ATTENDANCE(is_present, absence_reason_id, amount_charged).
  • Lesson data stays in LESSON, child data in CUSTOMER.

3NF · no transitive dependencies

  • Parent data repeated on every sibling → PARENT.
  • Tariff name and lesson count read from TARIFF, not copied.
  • Text categories → seven lookup tables referenced by id.

Columns kept on purpose

  • SUBSCRIPTION.price and ATTENDANCE.amount_charged freeze prices at the time of sale. The remaining credit is computed, never stored.
  • LESSON.subject_id is a fact of the lesson: groups rotate modules from week to week.
  • LESSON.branch_id is needed for lessons without a group; a trigger keeps it equal to the group's branch.

Declarative constraints

  • Every constraint is named (pk_, fk_, uk_, ck_), so errors say which rule failed.
  • Conditional checks: only clients have a study status; an invoice is for a subscription or a camp; a group lesson needs a group.
  • A camp invoice references CAMP_ENROLLMENT(camp_id, customer_id) through a composite foreign key.

Rules enforced by triggers

  • No attendance on a cancelled lesson, nor for a child outside the group.
  • Subscription, invoice and payment must belong to the same child.
  • Room, schedule and branch of a lesson must agree.
  • Invoice status follows its payments in both directions.
05 · Views

Six views for the club's daily questions

"Today" is fixed to the export date, 9 November 2026, so every view returns the same result whenever it is run.

06 · PL/SQL

Triggers, functions and procedures

Ten stored objects. Each raises a named application error (ORA-200xx) when a business rule is broken.

07 · Queries

Twenty business questions in SQL

Each query answers a real question the club asks and demonstrates one SQL technique: joins, grouping, subqueries, set operators, analytic functions and CTEs.

08 · Demonstration

The PL/SQL at work: 07_demo.sql

The demo script follows one new family from enrolment to payment, then tries six operations that the database must refuse.

  1. Attendance rate of the members of one group, computed by FN_ATTENDANCE_RATE.
  2. Enrolment: PRC_ENROLL_STUDENT locks the group, checks the free seats, branch and age, and turns the lead into a client.
  3. Package and invoice: a 4-lesson package at 520 lei; the invoice is checked by TRG_INVOICE_CONSISTENCY.
  4. Payment: the invoice becomes PAID; corrected to 300 lei it goes back to ISSUED; a second payment of 220 lei settles it again.
  5. Attendance: validated by TRG_ATTENDANCE_VALIDATE and priced at 520 / 4 = 130 lei by TRG_ATTENDANCE_CHARGE; FN_SUBSCRIPTION_CREDIT shows 390 lei left.
  6. Lesson generation: PRC_GENERATE_LESSONS creates the January 2027 lessons of a weekly schedule, skipping existing dates.
  7. Six refused operations: wrong age, double enrolment, attendance of a non-member, payment on another family's invoice, camp invoice without enrolment, invalid time.

Output

script07_demo.sqlThe full demonstration script›
09 · Run it

Run the project in Oracle

The scripts run in Oracle APEX (SQL Workshop → SQL Scripts → Upload) or any Oracle 19c+ schema. Run them in this order and check each result for errors.

#ScriptWhat it does
10 · Revision 2

What changed in this revision

Corrections made after a review of the first version, each checked against the data.

Model

Stored balance removed. SUBSCRIPTION.balance was 0 in all 653 rows and only an INSERT trigger maintained it. It is replaced by the frozen price; the credit left is computed by V_SUBSCRIPTION_USAGE and FN_SUBSCRIPTION_CREDIT.

Model

Camp invoices tied to enrolments. The foreign key now references CAMP_ENROLLMENT(camp_id, customer_id), so the database cannot bill a child for a camp they are not enrolled in.

Constraints

Times validated. 'HH24:MI' format checks on lessons and schedules; schedule date order; a GROUP lesson must have a group. 123 named constraints in total.

Triggers

Consistency of redundant columns. New TRG_ATTENDANCE_VALIDATE, TRG_LESSON_CONSISTENCY and TRG_INVOICE_CONSISTENCY. Analysis of the data showed that LESSON.subject_id legitimately differs from the group's subject in 267 lessons (module rotation), so it is documented rather than forced.

Triggers

Invoice status in both directions. TRG_PAYMENT_SETTLES_INVOICE is now a compound trigger that recomputes only the invoices touched, handles UPDATE and DELETE, and rejects a payment on another customer's invoice.

Procedures

Safer enrolment. PRC_ENROLL_STUDENT locks the group (FOR UPDATE), rejects double enrolments, ended groups and other branches, reports missing ids clearly and looks statuses up by name. PRC_GENERATE_LESSONS takes a start date.

Views & queries

V_STUDENT_ATTENDANCE and FN_ATTENDANCE_RATE count held lessons only; Q1 lists co-teachers with LISTAGG instead of repeating the lesson.

Housekeeping

A redundant index removed (39 left); the drop script also removes views, functions and procedures; the ERD shows the new relationship and column.