Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
In this lesson, we will build on the information we learned about Keys and Constraints to explain the concept of linking, or relating, tables in a database system.
One to Many relationships are by far the most common type of table relationship. There is a wealth of information about One to Many relationships available.
Here are a few of the links we find most helpful:
In the previous stages, we learnt about the high level concepts such as database
normalization and set theory.
We also learned about database keys and
how they are used to create database relationships.
Now, we're going to explore table relationships more in depth.
There are three types of relationships between tables.
They are called one to one, one to many, and many to many.
These types are described by how many rows can be related to each other
on either side of the relationship.
One to many relationships are by far the most common type of relationship,
that you'll encounter in database design.
This type of relationship means that one row in one table can be related to many
rows in another table at the other side of the relationship, but not vice versa.
The many can only happen in one direction.
Take this Sales Table for example,
it has a foreign key to the product table on the column ProductID.
When describing this relationship you could say, a Sale has 1 product but
a Product can be a many sales.
If you ever get confused as to which side is the foreign key,
an easy trick to remember is that the foreign key always goes on the many side.
In this example there are many instances of the ProductID, 145 on the Sale Table.
That's the many side, thus that's the foreign key.
In our next video, we'll take a look at the next type of relationship.
You need to sign up for Treehouse in order to download course files.Sign up