Lecture 5
Lecture 5
Customer(CustID, CustName)
Order(OrderID, CustID, OrderDate)
> CHANGE, EVERYDAY
To ensure that there are no orphan records, we need to enforce
referential integrity. An orphan record is one whose foreign key
FK value is not found in the corresponding entity – the entity
where the PK is located.
Recall that a typical join is between a PK and FK.
The referential integrity constraint states that the customer ID
(CustID) in the Order table must match a valid CustID in the
Customer table.
Most relational databases have declarative referential integrity.
In other words, when the tables are created the referential
integrity constraints are set up.
One to One
This relationship tells us that a single record in Table A is related to a single
record in Table B. And vice versa. Now, the moot question that may arise here
is, that why not move both the data into a single table. There may be many
reasons for it. One primary reason usually is security.
Let us look into an example: We have to create a table where details of our
name, age, email, address, telephone number and password needs to be
stored. Now, all of this are sensitive information and we would not want to
have them bundled together in a single table. Hence, to create a greater
security around it, we create a separate table for the password with different
access control, so that only a selected few will have access to it.EVERYDAY
> CHANGE,
One to Many
This type of relationship in a Database Management System
(DBMS) is the most common type of relationship.
This entails one data in Table A to have links to multiple data in
Table B. However, a single data in Table B, will have link to a
single data in Table A.
One good example to showcase such a relationship is through
a bank account. One individual may have multiple bank
accounts, but each bank account will be linked to one specific
owner or account holder only (provided we are not talking
about a joint bank account)