Normalization and Denormalization of Data

Learn about database design and how it helps create effective data retrieval.

Database design

A properly-designed database schema is essential for our query’s effectiveness. It will reduce the amount of data retrieval code we’ll have to write to retrieve data from the database later. For example, there’s a relationship between the books and authors models of the online bookshop application. A book can be written by different authors and an author can also write different books. How this relationship is saved in the database depends on the type of queries we run.

MongoDB, which is a NoSQL database, doesn’t enforce a schema by default unlike SQL databases like Postgres and MySQL. In a relational database, data is separated into different tables and is retrieved by queries using join statements to link and pull data from the different tables. This isn’t the case for NoSQL databases, which favor saving all the information about a model in a single collection instead.

Data normalization

Normalization is a term that refers to breaking and separating data into different tables to prevent data duplication and problems that might arise as a result of batch updates of data. Relationships between tables are referenced by the use of a foreign key. A foreign key is a primary key in another table that uniquely identifies a row of data.

Let’s look at the data design of a blog and its comments. A blog post might have multiple comments. In a relational database, both models are represented and saved in different tables.

Get hands-on with 1200+ tech skills courses.