No history yet

Introduction to Relational Databases

Organizing Information

Think about your phone's contact list. You have names, phone numbers, and maybe email addresses. Each contact is a neat little package of information. A database is just a way to organize information like this, but on a much larger scale.

A relational database is a specific type of database that organizes data into tables. The "relational" part comes from the way these tables can be linked together, showing relationships between different pieces of information. It’s like having a contact list, a separate to-do list, and a calendar, but being able to connect an event on your calendar to a specific person in your contacts. This structured approach is the most common way to manage data for everything from small businesses to massive corporations.

Tables, Rows, and Columns

The basic building block of a relational database is the table. A table stores information about a single subject, like Customers or Products. If you've ever used a spreadsheet, a table will look very familiar.

Each table is made up of columns and rows.

  • Columns are the vertical fields in the table. They define what kind of information is stored, like FirstName or Email. Each column is set up to hold a specific type of data, such as text, numbers, or dates.

  • Rows are the horizontal records in the table. Each row represents a single item. In our example, one row represents one customer, containing all the information about them across the different columns.

Schema

noun

The blueprint of a database. It describes how data is organized and how the tables relate to one another, including the names of tables, columns, and their data types.

Keeping Data Tidy

Imagine an online store where a customer's shipping address is spelled three different ways in three different places. Which one is correct? This is where data integrity comes in. It’s all about making sure the data in your database is accurate, consistent, and reliable.

Relational databases are great at this because they enforce rules. For instance, you can ensure that every order in an Orders table must be linked to a valid customer in the Customers table. You can also designate a column as a primary key, which is a unique identifier for each row. A CustomerID would be a perfect primary key because no two customers should have the same ID, just like no two students at a school have the same student ID number.

A primary key ensures every row in a table is unique and can be reliably identified.

Another important concept is normalization. This is just a fancy word for organizing your tables to reduce redundancy. The goal is to avoid storing the same piece of information more than once. Instead of typing out a customer's full name and address for every single order they place, you store the customer's information once in a Customers table. The Orders table then just needs to reference the customer's unique ID.

This way, if a customer moves, you only have to update their address in one place. Normalization makes your database more efficient and less prone to errors.

Lesson image

Why Use a Relational Database?

The relational model has been popular for decades for a few key reasons:

Consistency: The rules for data integrity ensure that your data stays accurate and reliable over time.

Flexibility: Because data is in separate, well-organized tables, you can combine it in countless ways to answer new questions you hadn't thought of before.

Scalability: Relational databases are built to grow. They can efficiently handle everything from a few dozen records to billions of them.

Simplicity: The table structure is intuitive and easy for people to understand, making it easier to work with the data.

Understanding this structure of tables, rows, and columns is the first step to mastering how to retrieve, manipulate, and manage data.

Ready to check your understanding?

Quiz Questions 1/5

What is the primary purpose of normalization in a relational database?

Quiz Questions 2/5

In a table of university students, which of the following would be the best choice for a primary key?

Now that you have a solid grasp of what a relational database is and how it's structured, you're ready to learn how to interact with one.