Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Now that we understand a little bit about what Relational Databases are and why we structure them the way we do, let’s take a higher-level look at how to think about data.
Set Theory was founded in 1874, and is a relatively new mathematical discipline, as compared to Algebra or Calculus.
For more history and info about the topic, check out the Wikipedia page on Set Theory
This link takes a look at Set Operations in SQL, but we’ll be covering this more in a later stage.
Now that we understand a little bit
about what relational databases are and
0:00
why we structure them
in the way that we do.
0:04
Let's take a high level look
at how to think about data.
0:07
You can think of a database table
as a set of data stored to a disk.
0:11
You can add and remove dates to
the set and you can update it.
0:15
When you query a table you get the whole
set or even a subset of data back.
0:20
This is known as a result set.
0:26
You may have notice me
saying the word settle up.
0:29
A set means a grouping
of similar things and
0:31
they are the foundation of performing
useful queries in relational databases.
0:34
Let's take a look at a few
examples of some simple sets.
0:39
Remember, a set means a grouping
of similar things together.
0:44
You could have a set of
things you can wear.
0:48
Shirts, shoes, socks, coats, or you could
have a more specific set of shirts.
0:50
T-shirt, dress-shirts, sweaters.
0:56
Items like shoes and socks belong in
the first set but not the second set.
1:00
You can wear socks and shoes but
they aren't types of a shirt.
1:05
Or you could have a set of fruits,
apples, bananas, strawberries, pears.
1:09
Or sets of apples, granny smith,
fugue, red delicious.
1:14
In this example,
the definition of the second set, apples,
1:18
excludes items from the more
inclusive set of all fruits.
1:22
You can also depicts sets conceptually
as graphs called the Venn diagrams.
1:28
These graphs help us show whereas one
set might overlap with another or
1:33
why one set is distinct from other sets.
1:37
Let's say we have a group of people
who like certain types of fruits and
1:41
we want to show who likes what.
1:45
We can depict this with Venn diagrams.
1:48
Here we have two small sets.
1:51
The sets of people who like apples and
the sets of people who like bananas.
1:53
The people who like apples are John,
Stacy, Indira and Bob.
1:58
And the people who like bananas
are Indira, Bob and Dante.
2:05
Now let's look at a common element for
both sets.
2:10
In this case, the elements are people.
2:14
As we overlay the two sets
you can see that both Bob and
2:17
Indira are the two people who
like both apples and bananas.
2:22
This area in the middle is called
the intersection between two sets.
2:26
The entirety of both circles combined,
2:31
in this case all people who like apples or
bananas, is called the union.
2:34
Finally, what if we want to just find
the people who like one fruit or
2:41
the other but not both.
2:46
This is called an except,
all people who like apples, and
2:48
all people who like bananas
except the people who like both.
2:52
When we perform an intersection, union or
2:58
except on sets of data,
these are known as set operations.
3:01
Remember, tables and the results
from queries a called data sets.
3:06
When you write a query for a port or
3:10
dynamic application,
you're actually working with datasets.
3:12
That can have set operations
performed on them.
3:17
Remember that a set is a collection
of similar things, a data set
3:20
is nothing more than a collection of
rows with the same column definitions.
3:25
A table is a data set that is
stored physically on a disk.
3:30
Let's take a look at our Venn
diagram example again, but
3:35
this time let's use data.
3:38
Here we see two small tables,
our group of people who like apples is in
3:41
one table and then the group of the other
people who like bananas in another.
3:46
Let's analyze that data for the people
who like both apples and bananas.
3:52
This is the intersection from
our Venn diagram a minute ago.
3:57
Now, let's see all people regardless
of which fruit they like.
4:01
This is the union from our Venn diagram.
4:06
And now let's look for just people that
like one fruit or the other, but not both.
4:08
This is the except example
from a minute ago.
4:14
This normalization process helps databases
perform set operations of intersection,
4:17
union, and except in fast and
efficient ways.
4:23
As we get deeper into this course,
we'll study this in more detail.
4:27
Keep the image of a Venn diagram in your
mind to help you visualize the concepts.
4:31
You need to sign up for Treehouse in order to download course files.
Sign up