Why Normalize a Database?

Normalizing a database means storing each fact once, in the table of the thing it describes, and linking the tables by identifiers instead of copying values from row to row. This guide follows one small example, a sheet of football players, from its flat form to its normalized form, and shows on that data what each form allows and what it costs.

A Flat Table Copies the Same Facts on Every Row

The starting point is a sheet with one row per player. Each row also carries the player's club, the club's city and the year the club was founded: five columns, two of them about the player, three about the club.

playersplayertextbornintegerclubtextclub_citytextclub_foundedinteger
The flat sheet as a schema: one table, where the columns about the club stand beside the columns about the player.
players
playerbornclubclub_cityclub_founded
Carles Puyol1978FC BarcelonaBarcelona1899
Paolo Maldini1968AC MilanMilan1899
Franco Baresi1960AC MilanMilan1899
Ryan Giggs1973Manchester UnitedManchester1878
Paul Scholes1974Manchester UnitedManchester1902
Francesco Totti1976AS RomaRome1927

AC Milan appears on two rows and Manchester United on two, so their city and founding year are written twice. The two Manchester United rows already disagree: Ryan Giggs's row says the club was founded in 1878, Paul Scholes's row (the cell in red) says 1902, the year the club took its current name.

Nothing in the sheet says which copy is right. Repeating a fact on several rows is called redundancy, and this is what it leads to: sooner or later two copies of the same fact differ.

The Same Data, Each Fact Stored Once

The normalized form gives each kind of thing a table of its own: players, clubs and cities. A player's row no longer copies the club's details. It holds the club's identifier, a pointer called a foreign key, and the club's row holds the identifier of its city in the same way.

🔑 Key: what tells two rows apartForeign key: points at one row of another table
club_idcity_idplayer🔑_idintegernametextbornintegerclub_idintegerclub🔑_idintegernametextfoundedintegercity_idintegercity🔑_idintegernametext
The normalized schema: three tables, each player pointing at one club and each club at one city.
city
_idname
1Barcelona
2Milan
3Manchester
4Rome
club
_idnamefoundedcity_id
1FC Barcelona18991
2AC Milan18992
3Manchester United18783
4AS Roma19274
player
_idnamebornclub_id
1Carles Puyol19781
2Paolo Maldini19682
3Franco Baresi19602
4Ryan Giggs19733
5Paul Scholes19743
6Francesco Totti19764

Manchester United's founding year is now written in one place, the club's own row. Ryan Giggs and Paul Scholes both point at club 3, so they cannot disagree about it. The six players, four clubs and four cities of the sheet are all still there; only the copies are gone.

What Normalization Makes Possible

Each of the eight points below comes from the same cause, a fact stored once, and each is shown on the example in both forms.

1. One correction applies everywhere

In the flat sheet

Correcting Manchester United's founding year means finding every row that names the club, two here and hundreds in a real sheet, and changing each one. A row that is missed keeps the old value, and the sheet disagrees with itself again.

In the normalized tables

The correction is one cell, the founding year of club 3. Every player pointing at club 3 reads the corrected value.

UPDATE club SET founded = 1878 WHERE _id = 3;

2. Nothing is lost, and nothing is blocked

In the flat sheet

Francesco Totti's row is the only one naming AS Roma: deleting it erases the club, its city and its founding year with him. In the other direction, a club with no player listed yet, such as Inter Milan, has no row to be written on.

In the normalized tables

Deleting player 6 leaves club 4, AS Roma, in place. Inter Milan is added as club 5 (the row in green) before any of its players, pointing at city 2, Milan, which is already there.

club
_idnamefoundedcity_id
4AS Roma19274
5Inter Milan19082

3. The database refuses inconsistencies

In the flat sheet

Nothing stops a seventh row from naming a club “Manchester Utd” in a city spelled “Manchestr”. To the sheet, that is a new club in a new city, and nobody is told.

In the normalized tables

The database checks every pointer: a player row pointing at club 9 is rejected, because no club has that identifier. When the club's name is declared as its key, a second row named “AC Milan” is rejected too.

INSERT INTO player (name, born, club_id) VALUES ('Xavi', 1980, 9);
-- refused: no row of club has _id = 9

4. New information is added in one place

In the flat sheet

Recording the country of each city adds a column to fill on all six rows, with “Italy” typed three times and “England” twice. Each new row repeats it again.

In the normalized tables

The country is one new column on the city table: four values, one per city (the cells in green). The player and club tables are not touched. A new kind of thing, such as stadiums, becomes a table of its own that clubs point at.

city
_idnamecountry
1BarcelonaSpain
2MilanItaly
3ManchesterEngland
4RomeItaly

5. Questions nobody planned for can be asked

In the flat sheet

“How many clubs were founded before 1900?” has no direct answer. The sheet has six rows for four clubs, so the clubs must first be told apart by their names, and Manchester United falls on both sides of 1900 depending on the row that is read.

In the normalized tables

The question is asked of the club table, which has one row per club: three clubs. “Which cities have several clubs?” is answered the same way, by counting the clubs pointing at each city.

SELECT count(*) FROM club WHERE founded < 1900;

6. Stable identifiers link the base to other systems

In the flat sheet

Another system, a ticketing tool or a CRM, can only match a club by its name, and “Man United”, “Manchester United” and “Manchester United F.C.” are three different texts.

In the normalized tables

The club has one identifier, 3, however its name is written. The other system stores that identifier, and a club that is renamed keeps every link to it.

7. A value translated once makes the whole base multilingual

In the flat sheet

“Milan” is written on every row of a Milan club. An Italian version of the sheet means translating the city on each of those rows, and keeping all the translations identical afterwards.

In the normalized tables

The city's name exists in one row, so it is translated once per language (the cells in green). Every club and every player pointing at city 2 then reads “Milano” in Italian, with no other row changed.

city
_idname (en)name (fr)name (it)
1BarcelonaBarceloneBarcellona
2MilanMilanMilano
3ManchesterManchesterManchester
4RomeRomeRoma

8. A thing cited a hundred times is completed once

In the flat sheet

Adding each club's stadium to the sheet means looking it up row by row: six lookups for four clubs, two of them done twice.

In the normalized tables

The stadium is looked up once per club: four lookups for six players. In a base where one club is cited by a hundred rows, ninety-nine lookups are saved, whether a person does them or a language model billed per request.

What Normalization Costs

Reading the data back takes more work. The flat sheet shows a player, the club and the city on one line. The normalized tables need a join: a query that follows the pointers from player to club to city to rebuild that line.

SELECT player.name, club.name AS club, city.name AS city, club.founded
FROM player
JOIN club ON club._id = player.club_id
JOIN city ON city._id = club.city_id;

Joins also take time on large tables. This is why reporting tools often read a flat copy rebuilt from the normalized tables: the copies exist again, but they are derived automatically and never edited by hand.

A flat table is enough when the data is written once and never corrected, when one person reads it by eye, or when it holds a single kind of thing with nothing repeated: a list of measurements, a log, an export made for one report.

Why It Is Rarely Done by Hand

Normalizing an existing sheet is four pieces of work: deciding which columns describe a thing of their own, choosing what tells two rows of that thing apart, recognizing that “Man United” and “Manchester United” are the same club, and rewriting every row as pointers. On six rows it takes minutes. On a sheet of fifty thousand rows it is a project, and part of it starts again each time a column is added.

Entity Enricher does these four steps from the data itself. It reads a sample and proposes the entities it describes, here players, clubs and cities, with the fields that identify each one, and the user accepts or changes the proposal. During enrichment, a semantic ID gives one identifier to a club written in several ways. A database sync then creates one table per kind of entity in a database the user owns, fills it, and applies a migration when the schema changes.

A field declared multilingual is filled in each requested language during the same run, once per entity, which is the seventh point above.