About this article

This article serves as an introduction to relational database concepts. This post is the first on a series exploring the subject of relational databases for the full-stack developer. Among other components, we define tables, columns, rows, relationships, identifiers, keys, indices, constraints, and schemas.

For quick access, here is the full list of the articles on the topic of relational database design:

  1. Introduction to Relational Databases (this article)
  2. Database Design: Entities, Attributes, and Relationships
  3. Database Design: Entity-Relationship Diagrams
  4. Database Design: Normalization
  5. Database Design: Entity-Relationship Diagram to Structured Query Language
  6. Deploying PostgreSQL for development and testing
  7. Structured Query Language Cheatsheet
  8. Working with databases from Python

Introduction

As a full-stack developer, you often work on projects that need to keep track of information. Online stores, blogs, games, and social media applications are a few of these types of projects.

For tracking information, persisting it between sessions, and querying it efficiently, nothing beats a database.

What is a database?

A database is an organized set of data stored electronically in a computer system. Databases required a software layer that serves as an interface between the data and the users. This layer is known as a database management system or DBMS.

There are many kinds of databases, but in general, you may label them as relational and non-relational databases. Relational databases are by far the most common. According to a ranking for April 2020, 7 out of the top 10 most popular databases are relational.

Table with the top ten database management systems.  Seven out of the ten are relational database management systems.

DB-Engines Ranking

You need databases to provide persistent storage to your applications, to permit concurrent access to data by multiple users or programs, and to protect data consistency.

Non-relational databases

There are many types of non-relational databases (also known as NoSQL). Each type has a niche use case. Some NoSQL database types are:

  1. Key-Value Stores (i.e., Redis)
  2. Document Stores (i.e., MongoDB)
  3. Search Engines (i.e., ElasticSearch)
  4. Wide Column Stores (i.e., Cassandra)
  5. Graph Databases (i.e., Amazon Neptune)

Relational databases

A relational database consists of a collection of organized, inter-related data.

Relational databases store items in tables, and strict rules define the structure of each table and the relationships between data in different tables.

Relational databases excel at storing and retrieving structured data and at ensuring atomicity, consistency, isolation, and durability (ACID) of database transactions.

Relational Database Components

Some important components of a relational database are:

  1. A table is a two-dimensional representation of a business entity we need to track. Tables contain columns and rows.
  2. Table columns represent the entity’s attributes or properties. Each column in a table should map to one and only one entity attribute. Each column has a data type.
  3. Table rows represent unique instances of the entity.
  4. An identifier is a column (attribute) we can use to identify rows (entity instances). They can be unique (identifies exactly one instance), non-unique (identifies several instances), or composite (consists of several columns).
  5. A primary key is a table’s unique identifier. Primary keys cannot be null and, once set, cannot be changed.
  6. A foreign key is a primary key in one table that we use as a non-unique identifier in another table. Foreign keys form relationships between two tables.
  7. A relationship is a link between rows in two different tables or rows in the same table. Relationships can be one-to-one, one-to-many, or many-to-many.
  8. An index is a data structure that improves the speed of data retrieval operations on a table.
  9. Structured query language or SQL is the language used by relational database management systems to write and retrieve data from the database.
  10. Constraints are rules added to our table definitions to enforce referential integrity and prevent logically incomplete data from being added to the database. Unique keys and foreign keys are important constraints. Other constraint examples are NOT NULL which rejects a record if a particular field is empty and UNIQUE which rejects a record if a field’s value is already present in another record.
  11. A database schema defines how tables are laid out and are related to other tables. Schemas include information about table columns, data types, constraints, and indices.

Relational Database Management Systems

There are several commercial relational databases. Some examples include Oracle, MS SQL Server, and IBM Db2.

For your projects, you are likely to use an open-source relational database like MariaDB, PostgreSQL, or SQLLite, among many others.

As of April 2020, the market split for relational databases is about 50% commercial and 50% open-source.

Conclusion

We hope you enjoyed this brief introduction to relational database concepts. In the next article, we explore relational database design, starting with the discovery of entities, attributes, and relationships. See you there!

References

You may also like:

Show CommentsClose Comments

Questions? Comments? Leave a reply to start a conversation...

%d bloggers like this: