No history yet

Introduction to Databases

Organizing Information

Think about a massive library. Books are everywhere. Without a system, finding a specific book would be a nightmare. You'd wander aimlessly for hours. But with a card catalog or a digital search system, you can find exactly what you need in seconds. That system is the key.

A database is a digital version of that organized system. Its job is to store, manage, and retrieve information efficiently. Instead of books, it handles data: customer details, product inventory, financial records, you name it. By keeping data organized, a database makes it easy to find and use information when you need it.

Lesson image

The most common type of database is a relational database. The name sounds complex, but the idea is simple. It organizes data into tables, which look a lot like spreadsheets. The “relational” part just means these tables can be linked together. This system for managing the database is called a Relational Database Management System, or RDBMS.

The Building Blocks

Every relational database is built from a few simple parts: tables, records, and fields.

Table: A container for related data. For example, you might have one table for customers and another for products. Field: A column in a table that holds a specific type of information, like FirstName or Price. Record: A row in a table that represents a single entry, like all the information for one specific customer.

Let’s look at a simple Customers table. Each column is a field, and each row is a unique record for one customer.

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

Connecting the Dots

Organizing data in tables is a great start, but the real power comes from connecting them. This is done using special fields called keys.

Primary Key

noun

A field that uniquely identifies each record in a table. Its value must be different for every row and it can't be empty.

The CustomerID field ensures we can always find a specific customer, even if two people have the same name. No two customers can have the same CustomerID.

Now, how do we know which customer placed an order? We create a separate table for orders and use a foreign key to link it back to our customers.

Foreign Key

noun

A field in one table that refers to the primary key in another table. It creates a link between the two tables.

Here’s an Orders table. Notice the CustomerID column. It contains values that match the CustomerID primary key in the Customers table.

OrderIDOrderDateAmountCustomerID
1012023-04-10$45.502
1022023-04-11$80.001
1032023-04-12$15.252

Looking at the Orders table, we can see that orders 101 and 103 were placed by the customer with CustomerID 2. We can look that up in the Customers table to see that Ana Trujillo placed those orders. This connection is a relationship. By linking tables this way, we avoid duplicating customer information in the Orders table and keep our data clean and efficient.

This structure is the foundation of almost every modern database. Understanding how tables, keys, and relationships work together is the first step toward managing data effectively.