DATABASE SYSTEMS • ORACLE SQL • DATABASE DESIGN

London Underground Event Database

A university Database Systems project involving the design and implementation of a relational database for transport event data. The project progressed from conceptual ER modelling through relational schema design and normalisation to an Oracle SQL implementation with constraints, queries, views and database logic.

Oracle SQL Database Design ER Modelling 3NF Joins Views Constraints Triggers

From transport events to a relational database.

The project models transport activity using individual passenger check-in and check-out events. Rather than assuming that complete journeys already existed in the source data, events were modelled explicitly and relationships were created between passengers, purchase media, stations, lines and transport events.

This provided the foundation for querying passenger activity, station usage, payment media and completed or incomplete journeys.

Entity Relationship Model

The database was first modelled conceptually using a Classic Chen Entity Relationship diagram. The model identifies the major entities, their attributes, relationships, cardinalities and participation constraints.

Conceptual ER model showing passengers, purchase media, stations, lines and transport events. Click the diagram to view it at full size.

Relational Table Schema

The conceptual model was converted into a relational schema with primary keys, foreign keys and an associative StationLine relation. StationLine resolves the many-to-many relationship between stations and lines using a composite key.

Relational schema showing table references and primary and foreign key relationships. Click the diagram to view it at full size.

Normalised to Third Normal Form

The relational design was analysed through First, Second and Third Normal Form. Attributes were separated into appropriate relations and dependencies were considered to reduce duplication and avoid insertion, update and deletion anomalies.

1NF

Atomic Data

Relations were structured so attributes contained atomic values and repeating groups were removed.

2NF

Key Dependencies

Non-key attributes were considered against their complete keys, including the composite key used by StationLine.

3NF

Transitive Dependencies

The final design separates data into relations so non-key attributes depend on the relevant key rather than other non-key attributes.

Oracle SQL Implementation

The relational design was implemented in Oracle SQL using table definitions, primary keys, foreign keys and integrity constraints. Test data was then used to validate relationships and query the resulting database.

CREATE TABLE StationLine (
    SID VARCHAR2(10),
    LID VARCHAR2(10),

    CONSTRAINT pk_stationline
        PRIMARY KEY (SID, LID),

    CONSTRAINT fk_stationline_station
        FOREIGN KEY (SID)
        REFERENCES Station(SID),

    CONSTRAINT fk_stationline_line
        FOREIGN KEY (LID)
        REFERENCES Line(LID)
);

Example of using a composite primary key and foreign-key constraints to represent the Station-Line relationship.

SQL Queries & Analysis

SQL queries were developed to retrieve, filter, combine and aggregate transport data. The work included filtering with WHERE, sorting, date formatting, aggregate functions, GROUP BY, inner joins, left joins and queries across related tables.

QUERY 01

Passenger Event Analysis

Passenger records were connected to purchase media and transport events using LEFT JOIN operations. Events were then counted for each passenger using aggregation.

LEFT JOIN COUNT GROUP BY
SELECT
    p.PID,
    p.FullName,
    COUNT(e.EID) AS TotalEvents
FROM Passenger p
LEFT JOIN PurchaseMedium pm
    ON p.PID = pm.PID
LEFT JOIN Event e
    ON e.TID = pm.TID
GROUP BY p.PID, p.FullName;

QUERY 02

Events by Line

Event records were grouped by line to calculate activity across the transport network.

COUNT GROUP BY
SELECT
    LID,
    COUNT(*) AS TotalEvents
FROM Event
GROUP BY LID;

QUERY 03

Passenger Payment Media

Passenger and purchase-medium relations were joined to identify passengers using card-based payment media.

JOIN WHERE Relational Query
SELECT
    p.PID,
    p.FullName,
    pm.TID,
    pm.MediumType
FROM Passenger p
JOIN PurchaseMedium pm
    ON p.PID = pm.PID
WHERE pm.MediumType = 'Card';

Queries & Database Views

The implemented database was tested in Oracle SQL using queries across related tables and reusable views. These outputs demonstrate joins, aggregation and higher-level analysis of transport events.

Views, Constraints & Validation

The implementation extended beyond individual queries by creating reusable database views and validation logic for common transport analysis tasks.

LatestEventPerMedium

Identifies the latest recorded event associated with each purchase medium.

CompletedJourneys

Combines related check-in and check-out events to support journey-level analysis including journey times and start and end stations.

EventCountPerStation

Aggregates event activity by station to provide a reusable station-level view.

PassengerCardSummary

Summarises purchase-media information associated with passenger records.

DATA INTEGRITY

Card Information Validation

Database logic was also implemented to validate card-related information when card payment media was used, adding an additional integrity check beyond the relational key structure.

Full SQL Source

The complete Oracle SQL implementation is included with this portfolio project. The source contains the database structure, relationships, constraints, sample data, validation logic and database views used by the project.

DATABASE.TXT

Run the Database

View or download the complete SQL source, copy its contents into an Oracle SQL environment such as Oracle LiveSQL, and execute the script to create and populate the database. The database can then be explored using SQL queries.

What the project covered

Oracle SQL Relational Databases ER Modelling Classic Chen Relational Schema Design 1NF 2NF 3NF Primary Keys Foreign Keys Composite Keys Constraints JOIN LEFT JOIN GROUP BY Aggregate Functions Views Triggers

Explore more work.