Relational Database Relationships

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 8

relational database relationships

one-to-one

one-to-many many too many so in this

video we're going to have an overview of

the three types of relationships we look

at for databases

in the ipt course okay so what we're

going to do is we're going to use the

movie rental system

database but that we've looked in a

previous activity okay

and as you can see there i've got the

entities of member rental and movie

from that actual database that we've

looked at before

but i've also included driver's license

here too just to show

another type of relationship as well so

hopefully i can illustrate all three

types of relationships in this video

so firstly is driver's license okay and

we've got all details about

a person's driver's details and this is

being used here

in logic to verify a member's details

okay so we can see that they're

authentic okay that's my justification

for using the entity

really i'm just using it here so i can


illustrate one of the actual

relationships

okay so secondly is the member and as i

said we're going to be justifying their

details

with their driver's license and you got

all their details so that they can be

referred to by the system and

be eligible to rent movies from the

system we've got

rental allowing actual members rents to

be recorded on the systems every time

they rent a movie

and then finally movie details okay the

movies they are renting

from the system so these are the four

entities we're going to be using here

to illustrate the three different type

of relationships of one to one one to

many and many to many

so firstly we're going to look at the

primary and foreign keys

in order to establish our relationships

so the first one is

a one-to-one relationship between member

and driver's licenses

every member has one driver's license

okay that they are going to use to

verify themselves
and one driver's license is only going

to be used to

validate one member okay so it is one to

one the records between each other

only correlate with one another between

those two entities

next is member and rental and that is a

one-to-many relationship

one member can make many rentals but

every rental only relates to one member

and then

finally is between movie and rental and

this is a many-to-many relationship

and in order to do that once again we

need a junction okay that junction has

two foreign keys within it

okay which are both primary keys of each

entity involved here

so they are many-to-many relationship as

one movie

can refer to multiple rentals and every

ramp tour can refer to multiple movies

in order to establish that relationship

so we've said the relationships we've

shown him in a schematic design but

let's have a look at what those

relationships actually look like when

we're referring to records because these

are all based on records referring to


each other

so firstly is the one-to-one

relationship where a single record in

one entity

is only referencing a single record in

another entity and that same record

obviously is only referencing it in

return

so let's look at members and driver's

licenses so

between member and driver's license okay

member id2 is only referencing driver

id2

and member id 6 is only referencing

driver id 6k

it only references one record in the

opposing entity

on the flip side of that of driver's

licenses to memphis it's exactly the

same

okay drivers id2 is only doing member

id2

driver id 6 is ending member idt so it's

exactly the same going both ways

one record one only references one in

the other okay

exactly the same way it is it is a

simple uh relationship okay one record

only representing one other record next


is the one-to-many relationship or the

many-to-one relationship

okay where a single record in one entity

may reference

multiple records in another entity

though within the other entity the

records may only reference a single

record in the initial entity

so as we've already stated member to

rentals

okay is a one-to-many relationship okay

so

one member okay member id2 make

multiple rentals so rental id 2 and

rental id 6

might both refer to member id 2. okay

one person has made two separate rentals

okay

another example is member id3 they might

have done the rental id 3 and rental id

and rental id 5. okay so those three

records

refer to that one specific member okay

but on the flip side of that when going

rentals

back to members okay we know that rental

id2

only refers to member id2 it doesn't


refer to any other member because only

one rental can be made by one member

and it's the same with rental id 2 it

only represents

member id2 okay so that justification so

it can only represent one record in that

entity but the member entity can

reference

multiple records in the rental entity

okay so that's what we've got to

understand with a one-to-many

relationship

finally we have the many-to-many

relationship and as we've already said

movies to rentals was our many-to-many

relationship

so movie id2 might be used in rental id

and rental id 6. okay and movie id3

may be using rental id3 and rental id4

and rental id5 okay so it is

going from the movies to the rentals one

to many

but we said it's exactly the same on the

flip side okay in rental id's the movie

and this is why we had to have the

junction

so going back the exact opposite way

rental id 2
okay might have involved movie id2 and

movie id3 both those movies were rented

during that rental

and rental id 3 could reference movie id

2 and movie id 3 as well exactly the

same but also movie id4

and movie id5 okay so both

entities can reference multiple records

in the other entity

thus establishing their many-to-many

relationship

so i hope this video has given you

understanding of relational database

relationships

a one-to-one relationship where one

record one entity can only reference one

record in another entity

a one-to-many relationship where one

record in one city

can reference many records in another

entity but on the flip side that other

entities records can only

reference one record in the initial

entity

and then finally the many-to-many

relationship where one record in one

entity can reference

multiple records in the other entity and

the records in the under


can do exactly the same they can

reference multiple records back

so i hope this helps clear that up to

you based on records in a relational

database

You might also like