Simplified
Simplified

L2.1Two kinds of database

YOU

Two kinds of database

Instagram'sserverdatabasestoringretrieving?
ContactsAAna555-0142BBen555-0178CCara555-0115your contactsnamephone numberemailyour contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.com?
beach postYyou···1/3you Beach dayMalibucoffee postYyou···you Coffee?
relationalrows and columnsnamephone numberAAna555-0142BBen555-0178CCara555-0115non-relationalother shapes?

Databases · Lesson 2.1

Kinds of Database

Two kinds of database

Simplified
0:00 / 1:06

Instagram's database stores your posts on disk, and retrieves them whenever the server sends a query.

But does every database keep its data in the same shape?

Well, think of the contacts on your phone.

Every contact has the same things: a name, a phone number and an email.

ContactsAAna555-0142BBen555-0178CCara555-0115your contactsnamephone numberemailyour contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.com?

So your contacts fit neatly in rows and columns, like a spreadsheet.

One row for each contact, and one column for each thing it has.

Now think of two of your Instagram posts.

One has a caption, 3 photos and a location.

Another has just a caption and 1 photo.

beach postYyou···1/3you Beach dayMalibucoffee postYyou···you Coffee?

Each post has different things in it.

That's why databases come in two kinds.

One kind keeps data in rows and columns, like your contacts.

That's called a relational database.

The other kind keeps data in other shapes, like one card for each post.

That's called a non-relational database.

relationalrows and columnsnamephone numberAAna555-0142BBen555-0178CCara555-0115non-relationalother shapes?

So the two kinds of databases differ in the shape they give your data.

Every database is one of two kinds, relational or non-relational.

And what sets them apart is the shape they give your data.

Example: Two kinds of database

Every alarm on your phone has a time, a label, and whether it's on.

Which kind of database keeps data in rows and columns like this?

Explanation

First, every alarm has the same three things.

Then, records with the same things fit rows and columns.

Therefore, a relational database keeps data like this.

Question 1

Databases come in two kinds, relational and non-relational.

Which of these describes a non-relational database?

Data that fits a grid

ContactsAAna555-0142BBen555-0178CCara555-0115your contactsnamephone numberemailyour contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.com?
My contactsABCD1Ana555-0142ana@mail.com2Ben555-0178ben@mail.com3Cara555-0115cara@mail.com4a row →↑ a column
table
data laid out in rows and columns, like a spreadsheet
contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.coma row →↑ a column

Databases · Lesson 2.2

Kinds of Database

Data that fits a grid

Simplified
0:00 / 0:46

Every phone contact has a name, a number and an email, so they fit neatly in rows and columns.

But what does a relational database actually look like inside?

Well, picture a spreadsheet, like one in Google Sheets.

It's a grid: rows go across, and columns go down.

My contactsABCD1Ana555-0142ana@mail.com2Ben555-0178ben@mail.com3Cara555-0115cara@mail.com4a row →↑ a column

A relational database keeps data in grids just like this.

Each grid is called a table.

A table is data laid out in rows and columns, like a spreadsheet.

contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.coma row →↑ a column

In your contacts table, each row is one contact, like Ana.

And each column is one thing every contact has, like a phone number.

So a relational database keeps data in tables of rows and columns.

Each row is one record, and each column is one thing every record has.

Example: Data that fits a grid

Your phone's contacts table holds 4 contacts, each with a name, a number and an email.

How many rows does the table have?

Explanation

First, each row is one contact.

Then, there are 4 contacts.

Therefore, the table has 4 rows.

Question 1

A bank statement is a table with one row for every payment, and columns for the date, who was paid and the amount. This month's statement lists 12 payments.

How many rows does it have?

rows

Question 2

A spreadsheet lists your contacts, one person per row, with a column for their name and a column for their email.

In a relational database, what is data laid out like this called?

Question 3

A shop keeps its products in a table, with a column each for the name, the price and how many are in stock.

What is one row of this table?

Question 4

A school keeps its students in a table, with one row per student and a column each for name, class and grade.

Which kind of database is this?

Question 5

A table holds 30 movies, with a column each for the title, the year and the rating.

How many values are in the year column?

values

Question 6

Which of these is laid out like a table in a relational database?

Data that doesn't fit a grid

contactsnamephone numberemailAAna555-0142ana@mail.comBBen555-0178ben@mail.comCCara555-0115cara@mail.coma row →↑ a column
beach postYyou···1/3you Beach dayMalibucoffee postYyou···you Coffee?
postscaptionphoto 1photo 2photo 3locationBeach dayMalibuCoffeepostscaptionphoto 1photo 2photo 3locationBeach dayMalibuCoffeeemptyemptyempty
beach postbeach post's documentBeach dayMalibucoffee postcoffee post's documentCoffee
document
one record kept together, holding only the things it has
beach postbeach post's documentBeach dayMalibucoffee postcoffee post's documentCoffee
dentist visitMON129:00team lunchFRI141:00Café RomaABC3 guests
beach postbeach post's documentBeach dayMalibucoffee postcoffee post's documentCoffee

Databases · Lesson 2.3

Kinds of Database

Data that doesn't fit a grid

Simplified
0:00 / 1:15

In a table, every row has the same columns, like every contact in your contacts table.

But your Instagram posts each have different things, so they don't fit one neat grid.

So how does a non-relational database keep them?

postscaptionphoto 1photo 2photo 3locationBeach dayMalibuCoffeepostscaptionphoto 1photo 2photo 3locationBeach dayMalibuCoffeeemptyemptyempty

Say you put both posts in one spreadsheet, with a column for everything a post can have.

So the coffee post, with just a caption and 1 photo, leaves most of its columns empty.

A non-relational database doesn't use a grid at all.

It keeps each post as its own card instead.

Each card lists just the things that post has, and nothing it doesn't.

Each card is called a document.

A document is one record kept together, holding only the things it has.

beach postbeach post's documentBeach dayMalibucoffee postcoffee post's documentCoffee

The beach post's document has a caption, 3 photos and a location.

The coffee post's has just a caption and 1 photo.

So two documents can hold different things.

Now what about the events on your calendar?

dentist visitMON129:00team lunchFRI141:00Café RomaABC3 guests

A dentist visit has just a time.

A team lunch has a time, a place and three guests.

So each event can be its own document, holding only what it has.

So a non-relational database keeps each record as its own document.

And each document holds only the things it needs.

Example: Data that doesn't fit a grid

One Instagram post has a location, and another has none.

Can both be documents in the same database?

Explanation

First, each post is kept as its own document.

Then, two documents can hold different things.

Therefore, yes, both can be documents.

Question 1

A recipe app keeps each recipe as a document. One recipe has a cooking time, and another has a video but no cooking time.

Can both be kept in the same database?

Question 2

An Instagram post with 3 photos is kept as one document, which holds everything the post has.

Where are its 3 photos kept?

Question 3

A recipe site keeps each recipe as its own document. One recipe has 5 steps and a photo, and another has 12 steps and no photo.

How many documents does the site keep for these 2 recipes?

documents

Question 4

A news app keeps each article as a document, so one article's document holds a video, and another's holds a photo gallery.

Which kind of database is the news app using?

Question 5

A post with a caption and 1 photo is kept in a table whose columns are caption, photo 1, photo 2, photo 3 and location.

What happens to the columns the post doesn't use?

Question 6

Which of these records fits being kept as documents best?

Which kind do most apps use?

relationalrows and columnsnamephone numberAAna555-0142BBen555-0178CCara555-0115non-relationalother shapes?
your postsYyouyour commentsYSo cool!on Ana's postYWowon Ben's postYLove thison Cara's post
relationalrows and columnsnamephone numberAAna555-0142BBen555-0178CCara555-0115non-relationalother shapes?

Databases · Lesson 2.4

Kinds of Database

Which kind do most apps use?

Simplified
0:00 / 0:44

A relational database keeps data in tables of rows and columns, and a non-relational one keeps each record as its own document.

So which kind do most apps use, and why?

Most databases are relational.

That's because most app data is connected: one thing belongs to another.

Well, think of your Instagram account.

Your posts belong to you, and so do the comments you leave on your friends' posts.

your postsYyouyour commentsYSo cool!on Ana's postYWowon Ben's postYLove thison Cara's post

Tables are great at keeping track of what belongs to what.

That's why most apps keep their data in a relational database.

And it's why you're learning relational databases first.

We'll come back to documents near the end of the program. For now, just know they exist.

Most databases are relational, because most app data is connected.

Example: Which kind do most apps use?

On Spotify, your playlists belong to you, and each playlist holds songs.

Which kind of database suits data like this?

Explanation

First, playlists belong to you, and songs belong to playlists, so the data is connected.

Then, tables are great at keeping track of what belongs to what.

Therefore, a relational database suits it.

Question 1

On YouTube, your videos belong to your channel, and each video has comments that belong to it.

What kind of data is this?

Question 2

Why are most databases relational?

Question 3

Which of these is connected data, where one thing belongs to another?

Question 4

Databases come in two kinds, relational and non-relational.

Which kind are you learning first in this program?

Question 5

On Airbnb, your bookings belong to your account, and each booking belongs to a home.

Which kind of database is great at keeping track of data like this?

Question 6

Most app data is connected, like users who have orders.

Which kind of database do most apps use?

Assistant

Highlight lesson text and click Ask AI, or type a question below.