No history yet

Introduction to Databases

What Is a Database?

Think of a database as a highly organized digital filing cabinet. Its job is to store vast amounts of information in a structured way, making it easy to find, manage, and update data whenever you need it. Without databases, finding a specific customer's order on an e-commerce site would be like searching for a single grain of sand on a beach.

The core purpose of a database is to bring order to data chaos.

From your social media feed to your bank account balance, databases power the applications you use every day. They work silently in the background, ensuring data is stored safely and can be retrieved in an instant.

The Relational Approach

The most common type of database is a relational database. The big idea here is simple: data is organized into tables that can be linked, or related, to one another. A system that manages this is called a Relational Database Management System, or RDBMS.

Imagine a library. You wouldn't cram all information onto a single, massive list. Instead, you might have one list for all the books, another for all the library members, and a third for tracking who has borrowed which book. A relational database works the same way, keeping different types of information in separate, tidy tables.

Tables, Rows, and Columns

Every relational database is built on a simple structure: tables made of columns and rows. It’s a lot like a spreadsheet.

Columns define the categories of information. Each column represents a specific attribute, like a person's first name, last name, or email address.

Rows contain the actual data. Each row is a single, complete record, like all the information for one specific person.

For example, a table for storing customer information might look like this:

CustomerIDFirstNameLastNameEmail
101AnyaSharmaanya.s@email.com
102BenCarterben.carter@email.com
103AnyaKima.kim@email.com

Here, CustomerID, FirstName, LastName, and Email are the columns. Each person's information forms a distinct row.

Connecting the Dots

Notice that we have two people named Anya. How can the database tell them apart reliably? It needs a unique identifier for each row. This is where keys come in.

Primary Key

noun

A column (or set of columns) that contains a unique value for each row in a table. It cannot be empty or duplicated.

In our Customers table, CustomerID is the primary key. Even if two customers share the same name, their CustomerID will always be different.

Now, how do we link tables together? Let's say we have another table for orders. To know which customer made which order, we use a foreign key.

Foreign Key

noun

A column in one table that is the primary key of another table. It acts as a link or bridge between the two tables.

By placing the CustomerID (the primary key from the Customers table) into the Orders table, we create a relationship. Now, we can easily look up all the orders placed by Ben Carter by using his unique ID, 102.

This simple system of tables and keys is the foundation of relational databases. It allows us to store complex information without creating a mess, ensuring our data is organized, consistent, and easy to work with. Understanding this structure is the first step to mastering how to ask questions of your data.