Premier League Predictor: Astro — Chapter 3, Exercise 2 ==================================================== TASK Explain why the add-team route looks up an existing team by name before creating a new one, and describe a real scenario where skipping that lookup would create a duplicate teams row for the same real club. SOLUTION Per Chapter 2's own design, a teams row is meant to represent one real football club permanently, regardless of which seasons it happens to compete in. A club that gets relegated doesn't stop existing — its teams row should simply stop having a season_teams row for the seasons it isn't competing in, and gain a new one again if it's later promoted back up. If the add-team route always ran a plain INSERT INTO teams without first checking whether a team with that name already exists, every single promotion of a previously-tracked club would create a brand new, second teams row for the exact same real club, rather than reusing its original one. Concrete scenario: Leicester City is tracked as teams.id = 7 during the 2023/24 season, then gets relegated and has no season_teams row for 2024/25. When Leicester City is promoted back up for the 2026/27 season and an admin adds "Leicester City" to that season, skipping the name lookup would INSERT a brand new row — say teams.id = 41 — for the same real club. The app would now have two separate team identities for one real team: historical predictions and results tied to id 7 would never connect to the club's new appearances tied to id 41, silently splitting one club's own history into two disconnected records. The WHERE name = ? lookup prevents exactly this: it finds the original teams.id = 7 row and reuses it, so the club's full history — past and present seasons alike — stays attached to one single, consistent team identity. WHY THIS WORKS AS AN ANSWER ---------------------------- It explains the real invariant the lookup protects (one permanent identity per real club) and gives a concrete, numbered example showing exactly how skipping the lookup would fracture a real club's own history across two disconnected rows.