A Short Overview of Databases

Before you jump into working with Metabase, it’s helpful to know a few key database terms.

Tables

Fundamentally, databases are collections of tables. Tables contain one or more columns and one or more rows. A row is made up of cells, and each cell has a value that corresponds to the column it falls under.

Here’s an example of a table:

Name Age
John 25
Jenny 31

Here, the columns are Name and Age. The first row contains two cells, one with John and one with 25, corresponding to the Name and Age columns, respectively.

Columns

All the cells in a column contain the same type of information. For example, in the sample table above, the Name column contains names in each cell, while the Age column lists ages.

Columns are also sometimes interchangeably referred to as fields. Each field has a type that describes what kind of data is stored in the field.

Examples of types:

Example

Reservations Table

Reservation ID Name Age
11 John 25
12 Jenny 31

In the above table, the Reservation ID field is the ID (primary key). The Name field is a string type and the Age field is a numerical type (specifically an Integer).

Relationships

Tables can contain references to other tables, which establishes a relationship between them.

For example, in our hypothetical car booking app’s database, we could have two tables: one for reservations (let’s call it Reservations) and one for customers, (we’ll call this one Customers).

To connect the reservation data to the corresponding customer data, you can use a foreign key. A foreign key is a special kind of field in a table that references the same column in a different table. Almost always, the field that the foreign key points to is the ID or primary key in the other table.

For example, in our hypothetical car booking app, we could connect each reservation in the Reservations table to the corresponding customer that made the reservation by having the Customer column of the reservation contain the same value as the ID column of the customer who made the reservation.

Reservations

Customer Date Car
11 12/20/2015 Toyota Camry
12 1/2/2016 Range Rover

Customers

ID Name Age
11 John 25
12 Jenny 31

If we wanted to analyze our hypothetical app’s database with Metabase, we could ask a question, like:

What's the average age of all customers who made reservations in February of 2015?

To do this, we’d open up the Reservation table, add a filter to only look at reservations between February 1 and February 28, 2015, and select Average of…. To select the average of Age specifically, we now put our foreign key to use and select Age from the Customers table that our Reservations table references.


Next: Asking questions

Now that we have a shared vocabulary and a basic understanding of databases, let’s learn more about exploring in Metabase