The Scheme of a Schema

The differences between a schema and schemaless database

Anne Hyacinthe
The Marcy Lab School
3 min readAug 4, 2020

--

The best way to learn new concepts is to know the 5Ws and H, but with this topic, not all of these are applicable so by the end of this blog you will know:

  1. What is a schema?
  2. How are schema and schemaless databases different?
  3. Why is each beneficial?

What is a schema and what does that mean for the data?

A schema is the structure of a database and it encapsulates things such as tables and columns. It allows for normalization and regulation of the data being entered into the database.

A schema database

So a schemaless database not having a schema allows for data to be entered in any manner the developer finds to be necessary but documents in the same collection closely resemble each other configurations.

A schemaless database

How are they different?

The first is that schema databases are written in SQL while schemaless databases are written in a NoSQL language (like MongoDB) and utilize JSON documents or key/value pairs. The second difference is that they are used in different types of databases: schemas are for relational databases while schemaless databases are non-relational. A relational database relies on the schemas outline, tables and columns so that relations can be set between tables.

This causes components of data entries to be separated and placed into their proper table. For example in the first table pictured above the author went to the authors table while the book went to the books table. But in the second picture, we see how a non-relational database instead keeps the entry together.

Why are each beneficial?

Because of their horizontal scalability, schemaless database scale almost effortlessly. To change the standard of data entry no work is needed. As seen above, only the last entry has an amt property. To do that, I didn’t have to add a column, all that I did was add the property to the JSON document. In a schema database, I at least have to add a column. And if I were to ignore a column that had a NOT NULL constraint, a schema database would not add that entry at all. I would have to alter the entire table to remove the column.

A schema database allows for the utmost clarity. The data is consistent and with constraints, you know exactly what you’ll be receiving such as whether it’s an integer or characters. The relationships between tables are also clear cut due to foreign and primary keys.

--

--