Premier League Database

Overview

I love soccer stats. So I built a SQL database with every Premier League match since 1992—over 20,000 games from Kaggle. The goal was to answer questions like "who's best at home?" or "biggest away wins" without manually crunching spreadsheets.

Data Source & Structure

I used a Kaggle dataset that includes all Premier League matches up to the current date. The main challenge was interpreting the FTR (Full Time Result) column, which only stores three values:

  • H — Home win
  • D — Draw
  • A — Away win

I created a custom function to translate these into wins, losses, and draws for each team:

  • Home win → 1 win for home team, 1 loss for away team
  • Draw → 1 draw for both teams
  • Away win → 1 loss for home team, 1 win for away team

The database aggregates these results into tables showing teams with the best home records, best away records, and overall most wins.

Technical Implementation

  • Stored procedure (UpdateTeamStats): Synchronizes the GoalsScored and GoalsConceded columns across the HomeTeam and AwayTeam tables, ensuring data integrity and accuracy.
  • Database trigger (UpdateTeamStatsTrigger): Automatically executes the UpdateTeamStats procedure after any insert or update operation on the relevant tables, keeping statistics in sync without manual intervention.
Database schema and tables Query results and team statistics Stored procedures and triggers