DEV Community

Cover image for Introduction to databases
Johnson Chidera
Johnson Chidera

Posted on

Introduction to databases

INTRODUCTION

In ancient days, humans stored data in cave paintings, cuneiform tablets and papyrus scrolls. With the invention of the computer, data storage became more automatic. At first, the flat file model was invented in the early 1970s by IBM where data was stored in a single table which consisted of text files with no markup and data separated by commas or delimiters. This method is inefficient in a number of ways: It is not scalable, it has limited query capabilities and data integrity and consistency was difficult.

In this article, we are going to delve into what a database is and the different types of modern database management systems that are in existence today.

WHAT IS A DATABASE (DB)

A database is a systematic collection of records in such a manner that it is easily accessible and organised.

WHAT IS A DATABASE MANAGEMENT SYSTEM (DBMS)

A database management system is a system designed to manage databases. It gives us the ability to add data, update data, create data and delete data using queries.

TYPES OF DATABASE MANAGEMENT SYSTEMS

There are different types of databases in existence today but we will be talking about some common databases:

  • Relational Database
  • Document Database
  • Graph Database
  • Key-Value Database

RELATIONAL DATABASE

A relational database is a type of database that organizes data in rows and columns and these rows and columns come together to form a table.
Relational databases give us functionality such as referential integrity which means that all the keys referenced are valid.
Relational databases use sql as its query language.

Below is an example of a simple relational database schema.

Image description

Relational databases have a lot of merits such as data consistency, data integrity and query optimization, there are also some demerits to it such as fixed schema meaning that the structure of the database has to be defined in advance and there are some issues with scalability since it poses challenges and is costly when trying to horizontally scale relational databases.

Popular relational databases are mysql, PostgreSQL and Microsoft sql server

DOCUMENT DATABASE

In this type of database, data is stored in a JSON like format which makes it easier to query the database especially if data sent between the server and client is also in this JSON format.

Below is an example of a JSON document.

{
  "_id": 1,
  "first_name": "Ify",
  "last_name": "Johnson",
  "email_address": "ify@books.com",
  "age": "23",
  "billing_address": {
    "address": "1, wobo street",
    "city": "port harcourt",
    "state": "rivers state",
    "postal_code": 500012,
    "country": "Nigeria"
  }
}

Enter fullscreen mode Exit fullscreen mode

A document database makes use of collections. Collections are used to group related documents together.

MongoDB is a great example of a document database.

Document databases support horizontal scaling where data can be distributed across multiple servers and can handle large amounts of data, they have flexible schemas and flexible query languages. Schemas can also evolve over time. Schemas can be removed or added without breaking your code or affecting existing data.
Check here for more details about document databases.

GRAPH DATABASE

A graph database is a type of database that stores data in nodes and forms a relationship between these nodes instead of storing data in tables like in a relational database or a document like in a document database.

Examples of query languages that can be used to query and manipulate a graph database includes:

Below is a diagram of a graph structure

Image description

Although graph databases are very flexible and performant, they can include complexity into simple data models and since it’s not like other NoSQL or relational databases, developers have to learn how to query and model graph data.

KEY-VALUE DATABASE

This kind of database uses a key-value format to store data, whereby the key is used as a unique identifier to retrieve its corresponding value.

A great example of a key-value database is Redis. Redis, which stands for remote dictionary server, is an in-memory key-value data storage.

Key-Value databases are highly scalable since it supports horizontal scaling, it also supports caching to improve read performance and thereby reduces the load on the database.

Check here for more details about key-value databases .

CONCLUSION

Different types of databases are in existence now, each serving a unique purpose. You don’t have to go for the trendiest or most popular database, simply find the database that suits your particular project needs. For example, a social media application can make use of the graph database and an e-commerce website can make use of a relational database.

Top comments (0)