No history yet

Introduction to Relational Databases

What's a Relational Database?

Imagine a digital filing cabinet. Instead of stuffing random papers into folders, you use a set of perfectly organized binders. Each binder is for one specific type of information — one for customers, one for products, and one for orders. Inside each binder, the information is laid out in neat tables.

That’s the basic idea of a relational database. It’s a system for storing and organizing data in a structured way. The “relational” part comes from its ability to connect, or relate, the information in different binders. You can easily see which customer placed which order, or which products are in that order. This makes it incredibly powerful for managing complex information without creating a mess.

A relational database is a type of database that stores and organizes data points with defined relationships for easy access.

The Building Blocks

Every relational database is built from a few simple components: tables, columns, and rows. Let's stick with our store example to see how they work.

Table

noun

A collection of related data held in a structured format within a database. It consists of columns and rows. Think of it as a single spreadsheet.

A table holds information about a single subject, like customers or products. Here’s a simple Customers table:

CustomerIDFirstNameLastNameEmail
1MariaAndersmaria.a@email.com
2AnaTrujilloana.t@email.com
3AntonioMorenoantonio.m@email.com

In this table, we have columns and rows.

  • Columns are the vertical fields that contain a specific type of information for every record. In our example, CustomerID, FirstName, LastName, and Email are columns. Each column has a defined data type, like a number, text, or a date.

  • Rows are the horizontal records, representing a single entry. The first row contains all the information for Maria Anders: her ID, first name, last name, and email. Each row represents one complete record for one customer.

Making Unique Connections

What if we have two customers named Ana Trujillo? How can the database tell them apart? It needs a way to guarantee every single row is unique. This is where keys come in.

A Primary Key is a column (or set of columns) that uniquely identifies each row in a table. A primary key’s value must be unique for each row, and it cannot be empty (or NULL).

In our Customers table, CustomerID is the perfect primary key. No two customers will ever have the same ID, even if they share a name. This gives us a foolproof way to reference a specific customer.

Now, let's add an Orders table to our database.

OrderIDOrderDateCustomerIDAmount
1012023-10-263$81.50
1022023-10-261$22.00
1032023-10-273$15.75

This table has its own primary key, OrderID, to uniquely identify each order. But notice the CustomerID column. How does the database know this refers to the customers in our other table? That’s the job of a foreign key.

A Foreign Key is a column in one table that refers to the primary key in another table. It's the glue that links tables together.

In the Orders table, CustomerID is a foreign key. It points back to the CustomerID primary key in the Customers table. This link, or relationship, lets us see that Antonio Moreno (CustomerID 3) placed two orders, and Maria Anders (CustomerID 1) placed one.

This relationship is the core concept of a relational database. It allows us to keep data organized in separate, logical tables while maintaining powerful connections between them. Instead of duplicating customer information for every single order, we simply reference it. This keeps the data clean, efficient, and easy to manage.

Quiz Questions 1/5

What is the primary purpose of a relational database?

Quiz Questions 2/5

In a Products table, what is the function of a ProductID column that uniquely identifies each product?

Now that you understand the basic structure of a relational database, you're ready to explore how to interact with one.