File notes/lectures_notes.md changed (mode: 100644) (index 0c32f72..5ca0025) |
... |
... |
CAR(VIN (PK), Make, Model, Year) |
851 |
851 |
DRIVER(State (PK), Licence\_number (PK), Name, Address)
|
DRIVER(State (PK), Licence\_number (PK), Name, Address)
|
852 |
852 |
INSURANCE(Policy\_Number (PK), Insured\_Car (FK to CAR.VIN), Insured\_Driver\_State (FK to DRIVER.State), Insured\_Driver\_Num (FK to DRIVER.Licence\_number), Rate)
|
INSURANCE(Policy\_Number (PK), Insured\_Car (FK to CAR.VIN), Insured\_Driver\_State (FK to DRIVER.State), Insured\_Driver\_Num (FK to DRIVER.Licence\_number), Rate)
|
853 |
853 |
PRICE(Stock\_number (PK), Car\_Vin (FK to CAR.VIN), Price, Margin)
|
PRICE(Stock\_number (PK), Car\_Vin (FK to CAR.VIN), Price, Margin)
|
854 |
|
](fig/rel_mod/CAR1)
|
|
|
854 |
|
](fig/rel_mod/car_01)
|
855 |
855 |
\
|
\
|
856 |
856 |
|
|
857 |
857 |
(Yes, we do need the state *and* the licence number to uniquely identify a driver's licence, since [many states use the same licence format](https://ntsi.com/drivers-license-format/).
|
(Yes, we do need the state *and* the licence number to uniquely identify a driver's licence, since [many states use the same licence format](https://ntsi.com/drivers-license-format/).
|
|
... |
... |
Exercise +.# |
1006 |
1006 |
AUTHOR(Ref, Name, Address)
|
AUTHOR(Ref, Name, Address)
|
1007 |
1007 |
BOOK(ISSN, AuthorRef, Title)
|
BOOK(ISSN, AuthorRef, Title)
|
1008 |
1008 |
GAINED-AWARD(Ref, Name, BookISSN, Year)
|
GAINED-AWARD(Ref, Name, BookISSN, Year)
|
1009 |
|
](fig/rel_mod/BOOK_Exo)
|
|
|
1009 |
|
](fig/rel_mod/book_exo)
|
1010 |
1010 |
\
|
\
|
1011 |
1011 |
|
|
1012 |
1012 |
For each relation, answer the following:
|
For each relation, answer the following:
|
|
... |
... |
Exercise +.# |
1022 |
1022 |
TRAIN(Ref (PK), Model, Year)
|
TRAIN(Ref (PK), Model, Year)
|
1023 |
1023 |
CONDUCTOR(CompanyID (PK), Name, ExperienceLevel)
|
CONDUCTOR(CompanyID (PK), Name, ExperienceLevel)
|
1024 |
1024 |
ASSIGNED-TO(TrainRef (PK, FK to TRAIN.Ref), ConductorID (PK, FK to CONDUCTOR.CompanyID), Date (PK))
|
ASSIGNED-TO(TrainRef (PK, FK to TRAIN.Ref), ConductorID (PK, FK to CONDUCTOR.CompanyID), Date (PK))
|
1025 |
|
](fig/rel_mod/TRAIN_Exo)
|
|
|
1025 |
|
](fig/rel_mod/train_exo)
|
1026 |
1026 |
\
|
\
|
1027 |
1027 |
|
|
1028 |
1028 |
#. What are the foreign keys in the ASSIGNED-TO relation? What are they refering?
|
#. What are the foreign keys in the ASSIGNED-TO relation? What are they refering?
|
|
... |
... |
Exercise +.# |
1078 |
1078 |

|
|
|
1081 |
|
](fig/rel_mod/building_room)
|
1082 |
1082 |
\
|
\
|
1083 |
1083 |
|
|
1084 |
1084 |
#. Give two possible tuples for the BUILDING relation, and two possible tuples for the ROOM relation such that the state is consistent.
|
#. Give two possible tuples for the BUILDING relation, and two possible tuples for the ROOM relation such that the state is consistent.
|
|
... |
... |
Solution +.# |
1170 |
1170 |
AUTHOR(Ref (PK), Name, Address)
|
AUTHOR(Ref (PK), Name, Address)
|
1171 |
1171 |
BOOK(ISSN (PK), AuthorRef (FK to AUTHOR.REF), Title)
|
BOOK(ISSN (PK), AuthorRef (FK to AUTHOR.REF), Title)
|
1172 |
1172 |
GAINED-AWARD(Ref (PK), Name, BookISSN (FK to BOOK.ISSN), Year)
|
GAINED-AWARD(Ref (PK), Name, BookISSN (FK to BOOK.ISSN), Year)
|
1173 |
|
](fig/rel_mod/BOOK_Sol)
|
|
|
1173 |
|
](fig/rel_mod/book_sol)
|
1174 |
1174 |
\
|
\
|
1175 |
1175 |
|
|
1176 |
1176 |
For the last question, the answer is yes: based on the ISSN of the book, we can retrieve the author of the book. Hence, knowing which book was awarded which year, by looking in the GAINED-AWARD table, gives us the answer to that question.
|
For the last question, the answer is yes: based on the ISSN of the book, we can retrieve the author of the book. Hence, knowing which book was awarded which year, by looking in the GAINED-AWARD table, gives us the answer to that question.
|
|
... |
... |
Solution +.# |
1212 |
1212 |

|
|
|
1215 |
|
](fig/rel_mod/character)
|
1216 |
1216 |
\
|
\
|
1217 |
1217 |
|
|
1218 |
1218 |
#. Inserting <"Ash", "Evil Dead"> into the **CHARACTER** relation would cause an error if the database was empty, since no movie with the primary key "Evil Dead" has been introduced yet: this would be a referential integrity constraint violation.
|
#. Inserting <"Ash", "Evil Dead"> into the **CHARACTER** relation would cause an error if the database was empty, since no movie with the primary key "Evil Dead" has been introduced yet: this would be a referential integrity constraint violation.
|
|
... |
... |
Solution to [%D %n (%T)](#problem:cinema) |
1301 |
1301 |
AUDITORIUM(ID (PK), Capacity, Theater (FK to THEATER.ID))
|
AUDITORIUM(ID (PK), Capacity, Theater (FK to THEATER.ID))
|
1302 |
1302 |
SHOWTIME(ID (PK), MovieId (FK to MOVIE.ID), AuditoriumId (FK to AUDITORIUM.ID), StartTime)
|
SHOWTIME(ID (PK), MovieId (FK to MOVIE.ID), AuditoriumId (FK to AUDITORIUM.ID), StartTime)
|
1303 |
1303 |
TICKETS(ID (PK), ShowTimeId (FK to SHOWTIME.ID), Price)
|
TICKETS(ID (PK), ShowTimeId (FK to SHOWTIME.ID), Price)
|
1304 |
|
](fig/rel_mod/CINEMA)
|
|
|
1304 |
|
](fig/rel_mod/cinema)
|
1305 |
1305 |
\
|
\
|
1306 |
1306 |
|
|
1307 |
1307 |
---
|
---
|
|
... |
... |
Solution to [%D %n (%T)](#problem:rel_model_bills) |
1316 |
1316 |
MEMBER(Name, Political Group, BTerm, ETerm, ID (PK))
|
MEMBER(Name, Political Group, BTerm, ETerm, ID (PK))
|
1317 |
1317 |
REPRESENTATIVE(Role (PK), Member (FK to MEMBER.ID))
|
REPRESENTATIVE(Role (PK), Member (FK to MEMBER.ID))
|
1318 |
1318 |
VOTE(Bill (PK, FK to BILL.ID), Member (PK, FK to MEMBER.ID))
|
VOTE(Bill (PK, FK to BILL.ID), Member (PK, FK to MEMBER.ID))
|
1319 |
|
](fig/rel_mod/BILL)
|
|
|
1319 |
|
](fig/rel_mod/bill)
|
1320 |
1320 |
\
|
\
|
1321 |
1321 |
|
|
1322 |
1322 |
For simplicity, we added an `ID` to our `MEMBER` and `BILL` relations. Note that having a "role" in the `MEMBER` relation to store the information about speaker, etc., would be extremely inefficient, since we would add an attribute to the ~435 members that would be `NULL`{.sqlmysql} in ~430 of them.
|
For simplicity, we added an `ID` to our `MEMBER` and `BILL` relations. Note that having a "role" in the `MEMBER` relation to store the information about speaker, etc., would be extremely inefficient, since we would add an attribute to the ~435 members that would be `NULL`{.sqlmysql} in ~430 of them.
|
|
... |
... |
CAMPUS (Address (PK), University (FK to UNIVERSITY.Name)) |
1337 |
1337 |
DEPARTMENT (Code (PK), Contact, CreationDate, University (FK to UNIVERSITY.Name))
|
DEPARTMENT (Code (PK), Contact, CreationDate, University (FK to UNIVERSITY.Name))
|
1338 |
1338 |
COURSE (Name (PK), CreditHours)
|
COURSE (Name (PK), CreditHours)
|
1339 |
1339 |
OFFERING (Department (PK, FK to DEPARTMENT.Name), Course (PK, FK to COURSE.Name), Code)
|
OFFERING (Department (PK, FK to DEPARTMENT.Name), Course (PK, FK to COURSE.Name), Code)
|
1340 |
|
](fig/rel_mod/UNIVERSITIES)
|
|
|
1340 |
|
](fig/rel_mod/universities)
|
1341 |
1341 |
\
|
\
|
1342 |
1342 |
|
|
1343 |
1343 |
|
|
|
... |
... |
MariaDB [HW_CONSTRAINTS_PART3]> SELECT * FROM Table_set_null; |
1923 |
1923 |

|
|
|
1926 |
|
](fig/rel_mod/prof_department)
|
1927 |
1927 |
\
|
\
|
1928 |
1928 |
|
|
1929 |
1929 |
~~~{.sqlmysql}
|
~~~{.sqlmysql}
|
|
... |
... |
Solution to [%D %n (%T)](#problem:address) |
4124 |
4124 |

|
|
|
4127 |
|
](fig/rel_mod/address)
|
4128 |
4128 |
\
|
\
|
4129 |
4129 |
|
|
4130 |
4130 |
@problem:address -- Solution to Q. -.#
|
@problem:address -- Solution to Q. -.#
|
|
... |
... |
Solution to [%D %n (%T)](#problem:profrevisited) |
4326 |
4326 |
LECTURE (Code (PK), Year (PK), Name, Instructor (FK to PROF.Login)
|
LECTURE (Code (PK), Year (PK), Name, Instructor (FK to PROF.Login)
|
4327 |
4327 |
STUDENT(Login (PK), Name, Registered, Major (FK to DEPARTMENT.Code))
|
STUDENT(Login (PK), Name, Registered, Major (FK to DEPARTMENT.Code))
|
4328 |
4328 |
GRADE (Login (PK, FK to STUDENT.Login), Grade (PK), LectureCode (FK to LECTURE.Code), LectureYear (FK to LECTURE.Year))
|
GRADE (Login (PK, FK to STUDENT.Login), Grade (PK), LectureCode (FK to LECTURE.Code), LectureYear (FK to LECTURE.Year))
|
4329 |
|
](fig/rel_mod/PROF_DEPARTMENT_EXTENDED)
|
|
|
4329 |
|
](fig/rel_mod/prof_department_extended)
|
4330 |
4330 |
\
|
\
|
4331 |
4331 |
|
|
4332 |
4332 |
For the other questions, refer to this code.
|
For the other questions, refer to this code.
|
|
... |
... |
Solution to [%D %n (%T)](#problem:coffee) |
4356 |
4356 |
CUSTOMER (CardNo (PK), Name, Email, FavCoffee (FK to COFFEE.Ref))
|
CUSTOMER (CardNo (PK), Name, Email, FavCoffee (FK to COFFEE.Ref))
|
4357 |
4357 |
SUPPLY (Provider (PK, FK to PROVIDEV.ID), Coffee (PK, FK to COFEE.Ref))
|
SUPPLY (Provider (PK, FK to PROVIDEV.ID), Coffee (PK, FK to COFEE.Ref))
|
4358 |
4358 |
PROVIDER (Name (PK), Email)
|
PROVIDER (Name (PK), Email)
|
4359 |
|
](fig/rel_mod/COFFEE)
|
|
|
4359 |
|
](fig/rel_mod/coffee)
|
4360 |
4360 |
\
|
\
|
4361 |
4361 |
|
|
4362 |
4362 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:roleplaying) |
4434 |
4434 |
QUEST(Name (PK), XP)
|
QUEST(Name (PK), XP)
|
4435 |
4435 |
COMPLETED-BY(Character (PK, FK to CHARACTER.Name), Quest (PK, FK to QUEST.Name))
|
COMPLETED-BY(Character (PK, FK to CHARACTER.Name), Quest (PK, FK to QUEST.Name))
|
4436 |
4436 |
SPECIAL-ITEM(Name (P), Quest (FK to QUEST.Name))
|
SPECIAL-ITEM(Name (P), Quest (FK to QUEST.Name))
|
4437 |
|
](fig/rel_mod/RPG)
|
|
|
4437 |
|
](fig/rel_mod/rpg)
|
4438 |
4438 |
\
|
\
|
4439 |
4439 |
|
|
4440 |
4440 |
---
|
---
|
|
... |
... |
Solution to [%D %n (%T)](#problem:sqlWorks) |
4575 |
4575 |
AUTHOR(Name (PK), Email)
|
AUTHOR(Name (PK), Email)
|
4576 |
4576 |
BOOK(ISBN (PK), Work (FK to WORK.Title), Published, Price)
|
BOOK(ISBN (PK), Work (FK to WORK.Title), Published, Price)
|
4577 |
4577 |
EBOOK(ISBN (PK), Work (FK to WORK.Title), Published, Price)
|
EBOOK(ISBN (PK), Work (FK to WORK.Title), Published, Price)
|
4578 |
|
](fig/rel_mod/WORK)
|
|
|
4578 |
|
](fig/rel_mod/work)
|
4579 |
4579 |
\
|
\
|
4580 |
4580 |
|
|
4581 |
4581 |
The solution to the next questions can be read from the following code:
|
The solution to the next questions can be read from the following code:
|
|
... |
... |
multivalued | the box have double lines | |
4704 |
4704 |
derived | the box have dotted lines |
|
derived | the box have dotted lines |
|
4705 |
4705 |
a key | the name of the attribute is underlined |
|
a key | the name of the attribute is underlined |
|
4706 |
4706 |
|
|
4707 |
|

|
|
|
4707 |
|

|
4708 |
4708 |
\
|
\
|
4709 |
4709 |
|
|
4710 |
|

|
|
|
4710 |
|

|
4711 |
4711 |
\
|
\
|
4712 |
4712 |
|
|
4713 |
4713 |
In the following, we'll focus on the relationship between the entities more than on the attributes of particular entities, so we'll sometimes simply draw
|
In the following, we'll focus on the relationship between the entities more than on the attributes of particular entities, so we'll sometimes simply draw
|
4714 |
4714 |
|
|
4715 |
|

|
|
|
4715 |
|

|
4716 |
4716 |
\
|
\
|
4717 |
4717 |
|
|
4718 |
4718 |
leaving the attributes un-specified (but that does not mean that they all have to be atomic) or even just
|
leaving the attributes un-specified (but that does not mean that they all have to be atomic) or even just
|
4719 |
4719 |
|
|
4720 |
4720 |
|
|
4721 |
|

|
|
|
4721 |
|

|
4722 |
4722 |
\
|
\
|
4723 |
4723 |
|
|
4724 |
4724 |
but that does not mean that the entity type have no attribute!
|
but that does not mean that the entity type have no attribute!
|
|
... |
... |
but that does not mean that the entity type have no attribute! |
4736 |
4736 |
|
|
4737 |
4737 |
$E_1$, … $E_n$ *participate* in R, $e_1$, …, $e_n$ *participate* in $r_1$, $n$ is the degree.
|
$E_1$, … $E_n$ *participate* in R, $e_1$, …, $e_n$ *participate* in $r_1$, $n$ is the degree.
|
4738 |
4738 |
|
|
4739 |
|

|
|
|
4739 |
|

|
4740 |
4740 |
\
|
\
|
4741 |
4741 |
|
|
4742 |
4742 |
Note that we can have Entity Set 1 = Entity Set 2, in which case we say the relation is recursive.
|
Note that we can have Entity Set 1 = Entity Set 2, in which case we say the relation is recursive.
|
|
... |
... |
Naming convention: |
4749 |
4749 |
- Drawing usually reads right to left, and up to down.
|
- Drawing usually reads right to left, and up to down.
|
4750 |
4750 |
|
|
4751 |
4751 |
|
|
4752 |
|

|
|
|
4752 |
|

|
4753 |
4753 |
\
|
\
|
4754 |
4754 |
|
|
4755 |
4755 |
|
|
|
... |
... |
Convenient, and sometimes mandatory, to give role names. |
4759 |
4759 |
|
|
4760 |
4760 |
If we want to stress that we are considering only one aspect of an entity (that is, a person is not only an employee, a company is not only an employer, but this aspect is crucial for the "EMPLOYS" relation):
|
If we want to stress that we are considering only one aspect of an entity (that is, a person is not only an employee, a company is not only an employer, but this aspect is crucial for the "EMPLOYS" relation):
|
4761 |
4761 |
|
|
4762 |
|

|
|
|
4762 |
|

|
4763 |
4763 |
|
|
4764 |
4764 |
We can also use it to make the "right-side" and the "left-side" of a recursive relationship explicit:
|
We can also use it to make the "right-side" and the "left-side" of a recursive relationship explicit:
|
4765 |
4765 |
|
|
4766 |
|

|
|
4767 |
|

|
|
|
4766 |
|

|
|
4767 |
|

|
4768 |
4768 |
|
|
4769 |
4769 |
Finally, we will sometimes use "Role Name of Entity 1 : Role Name of Entity 2" as a notation for the relation between them.
|
Finally, we will sometimes use "Role Name of Entity 1 : Role Name of Entity 2" as a notation for the relation between them.
|
4770 |
4770 |
For instance, we can write "Employer:Employee" to denote the "EMPLOYS" relation, and we will also use this notation when the relationship is between different entities, and write e.g. "PERSON:POSITION" for the "OCCUPIES" relation.
|
For instance, we can write "Employer:Employee" to denote the "EMPLOYS" relation, and we will also use this notation when the relationship is between different entities, and write e.g. "PERSON:POSITION" for the "OCCUPIES" relation.
|
|
... |
... |
STUDENT : TEAM | $M:N$ | "A student can participate in multiple team, a team can |
4793 |
4793 |
|
|
4794 |
4794 |
We indicate the ratio on the edges:
|
We indicate the ratio on the edges:
|
4795 |
4795 |
|
|
4796 |
|

|
|
|
4796 |
|

|
4797 |
4797 |
|
|
4798 |
4798 |
Note that reflexive relations can have any ratio as well.
|
Note that reflexive relations can have any ratio as well.
|
4799 |
4799 |
An example of $M:N$ recursive relation could be:
|
An example of $M:N$ recursive relation could be:
|
4800 |
4800 |
|
|
4801 |
|

|
|
|
4801 |
|

|
4802 |
4802 |
|
|
4803 |
4803 |
##### Participation Constraint
|
##### Participation Constraint
|
4804 |
4804 |
|
|
|
... |
... |
The participation can be total (a.k.a. existence dependency, the entity **must** |
4808 |
4808 |
|
|
4809 |
4809 |
Total is drawn with a double line, partial is drawn with a single line:
|
Total is drawn with a double line, partial is drawn with a single line:
|
4810 |
4810 |
|
|
4811 |
|

|
|
|
4811 |
|

|
4812 |
4812 |
|
|
4813 |
4813 |
This reads "a course **must** be offered by a department, but a department may or may not offer courses".
|
This reads "a course **must** be offered by a department, but a department may or may not offer courses".
|
4814 |
4814 |
|
|
|
... |
... |
We are dealing with moving aspects here: atributes on $1:1$, $1:N$, $N:1$ relati |
4825 |
4825 |
|
|
4826 |
4826 |
For instance, imagine that every phone uses exactly (= "at most and at least") one carrier, that a carrier can provide network to multiple phones, and that the average quality of the network is an attribute in this relationship:
|
For instance, imagine that every phone uses exactly (= "at most and at least") one carrier, that a carrier can provide network to multiple phones, and that the average quality of the network is an attribute in this relationship:
|
4827 |
4827 |
|
|
4828 |
|

|
|
|
4828 |
|

|
4829 |
4829 |
|
|
4830 |
4830 |
Then each instance of the relation would be of the form ("Phone X", "Carrier Y", "$9/10$") for some way of ranking the average quality from $0$ to $10$.
|
Then each instance of the relation would be of the form ("Phone X", "Carrier Y", "$9/10$") for some way of ranking the average quality from $0$ to $10$.
|
4831 |
4831 |
Note that, from the fact that the relationship is $N:1$, this means that there is only one tuple involving "Phone X": this means that the average quality could actually be seen as a property of _the phone_, and hence be migrated as an attribute to the phone side:
|
Note that, from the fact that the relationship is $N:1$, this means that there is only one tuple involving "Phone X": this means that the average quality could actually be seen as a property of _the phone_, and hence be migrated as an attribute to the phone side:
|
4832 |
4832 |
|
|
4833 |
|

|
|
|
4833 |
|

|
4834 |
4834 |
|
|
4835 |
4835 |
Note that we could *not* migrate the "average phone quality" to the "Carrier" side: imagine if we had the instances ("Phone X", "Carrier Y", "$9/10$") and ("Phone Z", "Carrier Y", "$3/10$"), then should the attribute of "Carrier Y" be "$9/10$" or "$3/10$": we have no way of deciding based on this model.
|
Note that we could *not* migrate the "average phone quality" to the "Carrier" side: imagine if we had the instances ("Phone X", "Carrier Y", "$9/10$") and ("Phone Z", "Carrier Y", "$3/10$"), then should the attribute of "Carrier Y" be "$9/10$" or "$3/10$": we have no way of deciding based on this model.
|
4836 |
4836 |
|
|
|
... |
... |
As an exercise, you can look at the relationships TEACHING, MENTORING and EMITED |
4842 |
4842 |
Of course, relationships can have a degree higher than two.
|
Of course, relationships can have a degree higher than two.
|
4843 |
4843 |
An example of a ternary relation could be:
|
An example of a ternary relation could be:
|
4844 |
4844 |
|
|
4845 |
|

|
|
|
4845 |
|

|
4846 |
4846 |
|
|
4847 |
4847 |
To determine cardinality ratio, one should fix all but one parameters, and wonder how many values of the remaining parameter can be in that relationship.
|
To determine cardinality ratio, one should fix all but one parameters, and wonder how many values of the remaining parameter can be in that relationship.
|
4848 |
4848 |
|
|
|
... |
... |
On the oppsite, Customer Y and Account K would be in relationship with only $1$ |
4852 |
4852 |
It is sometimes impossible to do without relations with arity greater than $2$.
|
It is sometimes impossible to do without relations with arity greater than $2$.
|
4853 |
4853 |
For instance, consider the following two diagrams:
|
For instance, consider the following two diagrams:
|
4854 |
4854 |
|
|
4855 |
|

|
|
|
4855 |
|

|
4856 |
4856 |
|
|
4857 |
|

|
|
|
4857 |
|

|
4858 |
4858 |
|
|
4859 |
4859 |
You should realize that they convey different information.
|
You should realize that they convey different information.
|
4860 |
4860 |
For instance, you can know for a fact that a person visit a library only if they bought something in it, while the second diagram de-correlate the act of buying with the visit to a library.
|
For instance, you can know for a fact that a person visit a library only if they bought something in it, while the second diagram de-correlate the act of buying with the visit to a library.
|
|
... |
... |
Similarly, the second diagram could give you a hint that a person that owns a co |
4862 |
4862 |
|
|
4863 |
4863 |
An example of recursive ternary relation could be:
|
An example of recursive ternary relation could be:
|
4864 |
4864 |
|
|
4865 |
|

|
|
|
4865 |
|

|
4866 |
4866 |
|
|
4867 |
4867 |
An example of relation of degree $4$ could be:
|
An example of relation of degree $4$ could be:
|
4868 |
4868 |
|
|
4869 |
|

|
|
|
4869 |
|

|
4870 |
4870 |
|
|
4871 |
4871 |
|
|
4872 |
4872 |
---
|
---
|
|
... |
... |
The **partial key** is an attribute, that, _when paired with an entity with whic |
4885 |
4885 |
|
|
4886 |
4886 |
Weak entities and identifying relationships have a double border, and partial key have a dotted underline, as follows:
|
Weak entities and identifying relationships have a double border, and partial key have a dotted underline, as follows:
|
4887 |
4887 |
|
|
4888 |
|

|
|
|
4888 |
|

|
4889 |
4889 |
|
|
4890 |
4890 |
The idea here is that we do not need to gather data about all the dependent in the world, or in isolation, but are interrested in dependent only if they are related to en employee in our database.
|
The idea here is that we do not need to gather data about all the dependent in the world, or in isolation, but are interrested in dependent only if they are related to en employee in our database.
|
4891 |
4891 |
Just having the name of a dependent is not enough to identify them, but having their name _and_ the SSN of the employee they are related to is enough.
|
Just having the name of a dependent is not enough to identify them, but having their name _and_ the SSN of the employee they are related to is enough.
|
|
... |
... |
If you need to have, for instance, a dependant connected to multiple employees, |
4895 |
4895 |
You may wonder why we do not represent weak entities simply as (composite, multi-valued) attributes of their owner type.
|
You may wonder why we do not represent weak entities simply as (composite, multi-valued) attributes of their owner type.
|
4896 |
4896 |
For instance, why would we use
|
For instance, why would we use
|
4897 |
4897 |
|
|
4898 |
|

|
|
|
4898 |
|

|
4899 |
4899 |
|
|
4900 |
4900 |
instead of
|
instead of
|
4901 |
4901 |
|
|
4902 |
|

|
|
|
4902 |
|

|
4903 |
4903 |
|
|
4904 |
4904 |
?
|
?
|
4905 |
4905 |
The answer depends whenever we need to have the ability to represent our weak entities (here, PET) as being in relationship with other entities (that can themselves be weak!), as follows:
|
The answer depends whenever we need to have the ability to represent our weak entities (here, PET) as being in relationship with other entities (that can themselves be weak!), as follows:
|
4906 |
4906 |
|
|
4907 |
|

|
|
|
4907 |
|

|
4908 |
4908 |
|
|
4909 |
4909 |
This would be impossible if PET was an attribute of FRIEND!
|
This would be impossible if PET was an attribute of FRIEND!
|
4910 |
4910 |
Whenever the pet entity type is involved in other relationships or not should help you in deciding which representation to chose.
|
Whenever the pet entity type is involved in other relationships or not should help you in deciding which representation to chose.
|
|
... |
... |
Whenever the pet entity type is involved in other relationships or not should he |
4915 |
4915 |
|
|
4916 |
4916 |
Another example of weak entity whose owner is weak as well could be:
|
Another example of weak entity whose owner is weak as well could be:
|
4917 |
4917 |
|
|
4918 |
|

|
|
|
4918 |
|

|
4919 |
4919 |
|
|
4920 |
4920 |
The idea being that the Health care provider cares about an insuree only if they are covered by them, and that they care about the doula only if they are currently helping one of their insuree.
|
The idea being that the Health care provider cares about an insuree only if they are covered by them, and that they care about the doula only if they are currently helping one of their insuree.
|
4921 |
4921 |
|
|
|
... |
... |
The two constraints can be written on the same side, and the $N$, $M$, $P$ ratio |
4933 |
4933 |
|
|
4934 |
4934 |
For instance,
|
For instance,
|
4935 |
4935 |
|
|
4936 |
|

|
|
|
4936 |
|

|
4937 |
4937 |
|
|
4938 |
4938 |
could be drawn as
|
could be drawn as
|
4939 |
4939 |
|
|
4940 |
|

|
|
|
4940 |
|

|
4941 |
4941 |
|
|
4942 |
4942 |
meaning that
|
meaning that
|
4943 |
4943 |
|
|
|
... |
... |
meaning that |
4946 |
4946 |
|
|
4947 |
4947 |
More generally, we have the following:
|
More generally, we have the following:
|
4948 |
4948 |
|
|
4949 |
|

|
|
|
4949 |
|

|
4950 |
4950 |
|
|
4951 |
4951 |
#### Crow's Foot Notation {#sec:Crow_foot}
|
#### Crow's Foot Notation {#sec:Crow_foot}
|
4952 |
4952 |
|
|
|
... |
... |
Every time a relationships have attributes, they are mapped to the resulting rel |
5029 |
5029 |
Let us look in more details at some of those steps.
|
Let us look in more details at some of those steps.
|
5030 |
5030 |
For strong entities, using steps 1 and 7, the following:
|
For strong entities, using steps 1 and 7, the following:
|
5031 |
5031 |
|
|
5032 |
|

|
|
|
5032 |
|

|
5033 |
5033 |
|
|
5034 |
5034 |
would give:
|
would give:
|
5035 |
5035 |
|
|
5036 |
5036 |

|
|
|
5039 |
|
](fig/rel_mod/desk)
|
5040 |
5040 |
\
|
\
|
5041 |
5041 |
|
|
5042 |
5042 |
|
|
5043 |
5043 |
And note that if Serial was a complex attribute, we would just "unfold" it, or decompose it, and make all the resulting attributes the primary key of the relation.
|
And note that if Serial was a complex attribute, we would just "unfold" it, or decompose it, and make all the resulting attributes the primary key of the relation.
|
5044 |
5044 |
If one of the attribute was at the same time multi-valued and composite, as follows:
|
If one of the attribute was at the same time multi-valued and composite, as follows:
|
5045 |
5045 |
|
|
5046 |
|

|
|
|
5046 |
|

|
5047 |
5047 |
|
|
5048 |
5048 |
Then we would obtain:
|
Then we would obtain:
|
5049 |
5049 |
|
|
5050 |
5050 |

|
|
|
5053 |
|
](fig/rel_mod/computer_user)
|
5054 |
5054 |
\
|
\
|
5055 |
5055 |
|
|
5056 |
5056 |
For relationships, things are a bit more complicated.
|
For relationships, things are a bit more complicated.
|
5057 |
5057 |
Consider the following:
|
Consider the following:
|
5058 |
5058 |
|
|
5059 |
|

|
|
|
5059 |
|

|
5060 |
5060 |
|
|
5061 |
5061 |
Since it is a $1:1$ relationship where one of the side has a partial constraint, we have the choice between two approaches.
|
Since it is a $1:1$ relationship where one of the side has a partial constraint, we have the choice between two approaches.
|
5062 |
5062 |
The foreign key approach would give:
|
The foreign key approach would give:
|
|
... |
... |
The foreign key approach would give: |
5064 |
5064 |

|
|
|
5067 |
|
](fig/rel_mod/mapping_relationships_01)
|
5068 |
5068 |
\
|
\
|
5069 |
5069 |
|
|
5070 |
5070 |
Note that we could also have added the foreign key on the side of ENT.B, referencing the key of ENT.A.
|
Note that we could also have added the foreign key on the side of ENT.B, referencing the key of ENT.A.
|
|
... |
... |
For the same diagram, the cross-reference approach would give: |
5076 |
5076 |
ENT.A(KeyA (PK))
|
ENT.A(KeyA (PK))
|
5077 |
5077 |
ENT.B(KeyB (PK))
|
ENT.B(KeyB (PK))
|
5078 |
5078 |
MAPPING(KeyA (PK, FK referencing ENT.A.KeyA), KeyB(FK referencing ENT.B.KeyB))
|
MAPPING(KeyA (PK, FK referencing ENT.A.KeyA), KeyB(FK referencing ENT.B.KeyB))
|
5079 |
|
](fig/rel_mod/MappingRelationships2)
|
|
|
5079 |
|
](fig/rel_mod/mapping_relationships_02)
|
5080 |
5080 |
\
|
\
|
5081 |
5081 |
|
|
5082 |
5082 |
Similarly, note that, in MAPPING, KeyB, or KeyA and KeyB, would also be valid primary keys, but that it makes more sense to have KeyA being the primary key, since we know that ENT.A has a total participation constraint, but ENT.B does not.
|
Similarly, note that, in MAPPING, KeyB, or KeyA and KeyB, would also be valid primary keys, but that it makes more sense to have KeyA being the primary key, since we know that ENT.A has a total participation constraint, but ENT.B does not.
|
5083 |
5083 |
|
|
5084 |
5084 |
If both participation constraints were total, as follows:
|
If both participation constraints were total, as follows:
|
5085 |
5085 |
|
|
5086 |
|

|
|
|
5086 |
|

|
5087 |
5087 |
|
|
5088 |
5088 |
Then we could use the merged relations approach, and get:
|
Then we could use the merged relations approach, and get:
|
5089 |
5089 |
|
|
5090 |
5090 |

|
|
|
5092 |
|
](fig/rel_mod/mapping_relationships_03)
|
5093 |
5093 |
\
|
\
|
5094 |
5094 |
|
|
5095 |
5095 |
We picked KeyA to be the primary key for the same reason as before.
|
We picked KeyA to be the primary key for the same reason as before.
|
|
... |
... |
Of course, if ENT.A and ENT.B are the same entity (that is, REL is recursive), w |
5099 |
5099 |
|
|
5100 |
5100 |

|
|
|
5102 |
|
](fig/rel_mod/mapping_relationships_04)
|
5103 |
5103 |
\
|
\
|
5104 |
5104 |
|
|
5105 |
5105 |
or
|
or
|
|
... |
... |
or |
5107 |
5107 |

|
|
|
5110 |
|
](fig/rel_mod/mapping_relationships_05)
|
5111 |
5111 |
\
|
\
|
5112 |
5112 |
|
|
5113 |
5113 |
depending on the approach we chose.
|
depending on the approach we chose.
|
|
... |
... |
Binary $1:N$ and binary $M:N$ relationships are dealt with in a similar way, usi |
5116 |
5116 |
The most difficult part of the mapping is with $n$-ary relationships: we have to use cross-reference approaches, but determining the primary key is not an easy task.
|
The most difficult part of the mapping is with $n$-ary relationships: we have to use cross-reference approaches, but determining the primary key is not an easy task.
|
5117 |
5117 |
Consider the following^[This developement was actually asked at <https://dba.stackexchange.com/q/232068/>.]:
|
Consider the following^[This developement was actually asked at <https://dba.stackexchange.com/q/232068/>.]:
|
5118 |
5118 |
|
|
5119 |
|

|
|
|
5119 |
|

|
5120 |
5120 |
|
|
5121 |
5121 |
The arity constraints here can be rephrased as:
|
The arity constraints here can be rephrased as:
|
5122 |
5122 |
|
|
|
... |
... |
Att. 1 → Att. 3 | Att. 2 → Att. 1 |
5290 |
5290 |
|
|
5291 |
5291 |
#### Notations
|
#### Notations
|
5292 |
5292 |
|
|
5293 |
|

|
|
|
5293 |
|

|
5294 |
5294 |
|
|
5295 |
5295 |
Or, more conveniently:
|
Or, more conveniently:
|
5296 |
5296 |
|
|
5297 |
|

|
|
|
5297 |
|

|
5298 |
5298 |
|
|
5299 |
5299 |
If an attribute is a foreign key to another, we will draw an arrow between relations:
|
If an attribute is a foreign key to another, we will draw an arrow between relations:
|
5300 |
5300 |
|
|
5301 |
|

|
|
|
5301 |
|

|
5302 |
5302 |
|
|
5303 |
5303 |
Note that:
|
Note that:
|
5304 |
5304 |
|
|
|
... |
... |
For each attribute $A$ of the relation whose primary key is $A_1, …, A_n$: |
5386 |
5386 |
- Remove $A$ from the original relation, and all the functional dependencies that implied it,
|
- Remove $A$ from the original relation, and all the functional dependencies that implied it,
|
5387 |
5387 |
- Add a foreign key from $\{A'_1, …, A'_k\}$ to their original counterparts in the original relation.
|
- Add a foreign key from $\{A'_1, …, A'_k\}$ to their original counterparts in the original relation.
|
5388 |
5388 |
|
|
5389 |
|

|
|
|
5389 |
|

|
5390 |
5390 |
|
|
5391 |
5391 |
becomes
|
becomes
|
5392 |
5392 |
|
|
5393 |
|

|
|
|
5393 |
|

|
5394 |
5394 |
|
|
5395 |
5395 |
|
|
5396 |
5396 |
Refinment: note that if more than one attribute depends of the same subset $\{A'_1, …, A'_k\}$, we will create two relations: that is useless, we could have created just one.
|
Refinment: note that if more than one attribute depends of the same subset $\{A'_1, …, A'_k\}$, we will create two relations: that is useless, we could have created just one.
|
5397 |
5397 |
For instance, considering
|
For instance, considering
|
5398 |
5398 |
|
|
5399 |
|

|
|
|
5399 |
|

|
5400 |
5400 |
|
|
5401 |
5401 |
applying the algorithm would give
|
applying the algorithm would give
|
5402 |
5402 |
|
|
5403 |
|

|
|
|
5403 |
|

|
5404 |
5404 |
|
|
5405 |
5405 |
whereas a more subtle algorithm would give
|
whereas a more subtle algorithm would give
|
5406 |
5406 |
|
|
5407 |
|

|
|
|
5407 |
|

|
5408 |
5408 |
|
|
5409 |
5409 |
Note that in both cases, all the relations are in Second Normal Form, though.
|
Note that in both cases, all the relations are in Second Normal Form, though.
|
5410 |
5410 |
|
|
|
... |
... |
For each attribute $A$ of the relation whose primary key is $A_1, …, A_n$: |
5435 |
5435 |
|
|
5436 |
5436 |
We can have a look at another example:
|
We can have a look at another example:
|
5437 |
5437 |
|
|
5438 |
|

|
|
|
5438 |
|

|
5439 |
5439 |
|
|
5440 |
5440 |
Note that \{State, Driver\_Licence\_Num\}, would be a valid primary key for this relation, and that adding it would make it a relation in 1NF.
|
Note that \{State, Driver\_Licence\_Num\}, would be a valid primary key for this relation, and that adding it would make it a relation in 1NF.
|
5441 |
5441 |
|
|
|
... |
... |
As we can see, the name "Driver" is somehow counter-intuitive, since the relatio |
5443 |
5443 |
This relation is actually not in 2NF, because the FD \{State, Driver\_Licence\_Num\} → Governor is not fully functional.
|
This relation is actually not in 2NF, because the FD \{State, Driver\_Licence\_Num\} → Governor is not fully functional.
|
5444 |
5444 |
A possible way to fix it is to get:
|
A possible way to fix it is to get:
|
5445 |
5445 |
|
|
5446 |
|

|
|
|
5446 |
|

|
5447 |
5447 |
|
|
5448 |
5448 |
As you can see, the 2NF helped us in separating properly the entities.
|
As you can see, the 2NF helped us in separating properly the entities.
|
5449 |
5449 |
|
|
5450 |
5450 |
An example of a relation that is in 2NF but not in 3NF could be:
|
An example of a relation that is in 2NF but not in 3NF could be:
|
5451 |
5451 |
|
|
5452 |
|

|
|
|
5452 |
|

|
5453 |
5453 |
|
|
5454 |
5454 |
As we can see, all the non-prime attributes are fully functionaly dependent from Login, which is our primary key.
|
As we can see, all the non-prime attributes are fully functionaly dependent from Login, which is our primary key.
|
5455 |
5455 |
But, obviously, one of this dependecy is transitive, and breaks the 3NF.
|
But, obviously, one of this dependecy is transitive, and breaks the 3NF.
|
5456 |
5456 |
A way to fix it is:
|
A way to fix it is:
|
5457 |
5457 |
|
|
5458 |
|

|
|
|
5458 |
|

|
5459 |
5459 |
|
|
5460 |
5460 |
As we can see, 3NF also helped us in separating properly the entities, in a slightly different way.
|
As we can see, 3NF also helped us in separating properly the entities, in a slightly different way.
|
5461 |
5461 |
|
|
|
... |
... |
Would it make sense to be have a total participation constraint on one side, and |
5651 |
5651 |
Exercise +.#
|
Exercise +.#
|
5652 |
5652 |
|
|
5653 |
5653 |
: Express the constraints represented in the following diagram in plain English.
|
: Express the constraints represented in the following diagram in plain English.
|
5654 |
|

|
|
|
5654 |
|

|
5655 |
5655 |
|
|
5656 |
5656 |
Exercise +.#
|
Exercise +.#
|
5657 |
5657 |
|
|
|
... |
... |
Exercise +.# |
5726 |
5726 |
~
|
~
|
5727 |
5727 |
Convert the following ER diagram into a relational model:
|
Convert the following ER diagram into a relational model:
|
5728 |
5728 |
|
|
5729 |
|

|
|
|
5729 |
|

|
5730 |
5730 |
|
|
5731 |
5731 |
Exercise +.#
|
Exercise +.#
|
5732 |
5732 |
|
|
|
... |
... |
Exercise +.# |
5877 |
5877 |
~
|
~
|
5878 |
5878 |
Consider the following diagram:
|
Consider the following diagram:
|
5879 |
5879 |
|
|
5880 |
|

|
|
|
5880 |
|

|
5881 |
5881 |
|
|
5882 |
5882 |
Give the number of attributes for both classes, and suggest two operations for the class that does not have any. Discuss the multiplicities: why did the designer picked those values?
|
Give the number of attributes for both classes, and suggest two operations for the class that does not have any. Discuss the multiplicities: why did the designer picked those values?
|
5883 |
5883 |
|
|
|
... |
... |
Exercise +.# |
5885 |
5885 |
~
|
~
|
5886 |
5886 |
Convert the following E.R. diagram to a U.M.L. class diagram.
|
Convert the following E.R. diagram to a U.M.L. class diagram.
|
5887 |
5887 |
|
|
5888 |
|
: 
|
|
|
5888 |
|
: 
|
5889 |
5889 |
|
|
5890 |
5890 |
Exercise +.#
|
Exercise +.#
|
5891 |
5891 |
|
|
|
... |
... |
Exercise +.# |
5901 |
5901 |
|
|
5902 |
5902 |
Convert the following E.R. diagram into a U.M.L. class diagram:
|
Convert the following E.R. diagram into a U.M.L. class diagram:
|
5903 |
5903 |
|
|
5904 |
|

|
|
|
5904 |
|

|
5905 |
5905 |
|
|
5906 |
5906 |
|
|
5907 |
5907 |
## Solution to Exercises {-}
|
## Solution to Exercises {-}
|
|
... |
... |
To have statistics about the extensions, to sort the username by length, etc. |
5917 |
5917 |
|
|
5918 |
5918 |
Solution +.#
|
Solution +.#
|
5919 |
5919 |
|
|
5920 |
|
: 
|
|
|
5920 |
|
: 
|
5921 |
5921 |
|
|
5922 |
5922 |
Solution +.#
|
Solution +.#
|
5923 |
5923 |
|
|
5924 |
|
: 
|
|
|
5924 |
|
: 
|
5925 |
5925 |
|
|
5926 |
5926 |
Solution +.#
|
Solution +.#
|
5927 |
5927 |
|
|
|
... |
... |
Solution +.# |
5929 |
5929 |
|
|
5930 |
5930 |
Solution +.#
|
Solution +.#
|
5931 |
5931 |
|
|
5932 |
|
: 
|
|
|
5932 |
|
: 
|
5933 |
5933 |
|
|
5934 |
5934 |
Solution +.#
|
Solution +.#
|
5935 |
5935 |
|
|
|
... |
... |
Solution +.# |
5983 |
5983 |
|
|
5984 |
5984 |
Solution +.#
|
Solution +.#
|
5985 |
5985 |
|
|
5986 |
|
: 
|
|
|
5986 |
|
: 
|
5987 |
5987 |
|
|
5988 |
5988 |
Solution +.#
|
Solution +.#
|
5989 |
5989 |
|
|
|
... |
... |
Solution +.# |
5992 |
5992 |
|
|
5993 |
5993 |
Solution +.#
|
Solution +.#
|
5994 |
5994 |
|
|
5995 |
|
: 
|
|
|
5995 |
|
: 
|
5996 |
5996 |
|
|
5997 |
5997 |
Solution +.#
|
Solution +.#
|
5998 |
5998 |
|
|
5999 |
|
: 
|
|
|
5999 |
|
: 
|
6000 |
6000 |
|
|
6001 |
6001 |
Solution +.#
|
Solution +.#
|
6002 |
6002 |
|
|
|
... |
... |
Solution +.# |
6009 |
6009 |
|
|
6010 |
6010 |
We could have the following:
|
We could have the following:
|
6011 |
6011 |
|
|
6012 |
|

|
|
|
6012 |
|

|
6013 |
6013 |
|
|
6014 |
6014 |
Solution +.#
|
Solution +.#
|
6015 |
6015 |
~
|
~
|
6016 |
6016 |
|
|
6017 |
6017 |
We could have the following:
|
We could have the following:
|
6018 |
6018 |
|
|
6019 |
|

|
|
|
6019 |
|

|
6020 |
6020 |
|
|
6021 |
6021 |
Solution +.#
|
Solution +.#
|
6022 |
6022 |
|
|
|
... |
... |
Solution +.# |
6041 |
6041 |
|
|
6042 |
6042 |
A possible solution is:
|
A possible solution is:
|
6043 |
6043 |
|
|
6044 |
|

|
|
|
6044 |
|

|
6045 |
6045 |
|
|
6046 |
6046 |
Note that the two composite attributes are "generic", in the sense that you can re-use those examples easily.
|
Note that the two composite attributes are "generic", in the sense that you can re-use those examples easily.
|
6047 |
6047 |
|
|
|
... |
... |
Solution +.# |
6055 |
6055 |

|
|
|
6058 |
|
](fig/rel_mod/person)
|
6059 |
6059 |
\
|
\
|
6060 |
6060 |
|
|
6061 |
6061 |
Note that "Stays_At" could also be a separate relation, with two attributes, "Address" and "Person", linked to respectively PLACE.Address and PERSON.SSN, and both being the primary key of the relation.
|
Note that "Stays_At" could also be a separate relation, with two attributes, "Address" and "Person", linked to respectively PLACE.Address and PERSON.SSN, and both being the primary key of the relation.
|
|
... |
... |
Problem (Reverse engineering by hand) +.#Reverse-Engineering-ACTOR |
6293 |
6293 |
|
|
6294 |
6294 |
Look at the following relational model, and "reverse-engineer" it to obtain an E.R. diagram:
|
Look at the following relational model, and "reverse-engineer" it to obtain an E.R. diagram:
|
6295 |
6295 |
|
|
6296 |
|

|
|
|
6296 |
|

|
6297 |
6297 |
|
|
6298 |
6298 |
---
|
---
|
6299 |
6299 |
|
|
|
... |
... |
Problem (From E.R. diagram to Relational model -- BIKE) +.#ERtoRELBike |
6330 |
6330 |
|
|
6331 |
6331 |
Consider the following E.R. diagram:
|
Consider the following E.R. diagram:
|
6332 |
6332 |
|
|
6333 |
|

|
|
|
6333 |
|

|
6334 |
6334 |
\
|
\
|
6335 |
6335 |
|
|
6336 |
6336 |
_Based on this diagram_, answer the following: "Is it true that …"
|
_Based on this diagram_, answer the following: "Is it true that …"
|
|
... |
... |
Problem (From E.R. diagram to Relational model -- RECORD) +.#ERtoRELRecord |
6356 |
6356 |
|
|
6357 |
6357 |
Consider the following E.R. diagram:
|
Consider the following E.R. diagram:
|
6358 |
6358 |
|
|
6359 |
|

|
|
|
6359 |
|

|
6360 |
6360 |
\
|
\
|
6361 |
6361 |
|
|
6362 |
6362 |
_Based on this diagram_, is it true that …
|
_Based on this diagram_, is it true that …
|
|
... |
... |
Problem (ER-to-Relation mapping for Country) +.#ERtoRELCountry |
6382 |
6382 |
|
|
6383 |
6383 |
Consider the following E.R. schema:
|
Consider the following E.R. schema:
|
6384 |
6384 |
|
|
6385 |
|

|
|
|
6385 |
|

|
6386 |
6386 |
\
|
\
|
6387 |
6387 |
|
|
6388 |
6388 |
where
|
where
|
|
... |
... |
Problem (PRINT relation in third normal form) +.#print |
6657 |
6657 |
|
|
6658 |
6658 |
Normalize the following relation to the third normal form.
|
Normalize the following relation to the third normal form.
|
6659 |
6659 |
|
|
6660 |
|
{width=90%}
|
|
|
6660 |
|
{width=90%}
|
6661 |
6661 |
|
|
6662 |
6662 |
Do not forget to indicate all the primary keys in your relations.
|
Do not forget to indicate all the primary keys in your relations.
|
6663 |
6663 |
|
|
|
... |
... |
Problem (From E.R. to relational schema and UML class diagram -- CAR\_INFO) +.#c |
6732 |
6732 |
|
|
6733 |
6733 |
Consider the following E.R. schema for the CAR\_INFO database:
|
Consider the following E.R. schema for the CAR\_INFO database:
|
6734 |
6734 |
|
|
6735 |
|

|
|
|
6735 |
|

|
6736 |
6736 |
|
|
6737 |
6737 |
Note that a car can have at most one driver, $N$ passengers, $N$ insurances, and that car insurances exist only if they are "tied up" to a car (i.e., they are weak entities, and their identifying relationship is called "Insured").
|
Note that a car can have at most one driver, $N$ passengers, $N$ insurances, and that car insurances exist only if they are "tied up" to a car (i.e., they are weak entities, and their identifying relationship is called "Insured").
|
6738 |
6738 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:car-insurance) |
6833 |
6833 |
|
|
6834 |
6834 |
and
|
and
|
6835 |
6835 |
|
|
6836 |
|

|
|
|
6836 |
|

|
6837 |
6837 |
\
|
\
|
6838 |
6838 |
|
|
6839 |
6839 |
---
|
---
|
|
... |
... |
Solution to [%D %n (%T)](#problem:job-offers) |
6843 |
6843 |
|
|
6844 |
6844 |
A possible solution is:
|
A possible solution is:
|
6845 |
6845 |
|
|
6846 |
|

|
|
|
6846 |
|

|
6847 |
6847 |
\
|
\
|
6848 |
6848 |
|
|
6849 |
6849 |
Note that CONTACT could be a weak entity, with the identifying relationship being either DISCUSSED_BY or EMPLOYS, but both have disadvantages, since they would disallow a CONTACT to discuss more than one offer, or to be hired by more than one company.
|
Note that CONTACT could be a weak entity, with the identifying relationship being either DISCUSSED_BY or EMPLOYS, but both have disadvantages, since they would disallow a CONTACT to discuss more than one offer, or to be hired by more than one company.
|
|
... |
... |
Solution to [%D %n (%T)](#problem:ERtoRELBike) |
6869 |
6869 |
For the $1:M$ relationships that are not identifying, we can chose between the foreign key and the cross-reference approaches.
|
For the $1:M$ relationships that are not identifying, we can chose between the foreign key and the cross-reference approaches.
|
6870 |
6870 |
If we use the former, we obtain:
|
If we use the former, we obtain:
|
6871 |
6871 |
|
|
6872 |
|

|
|
|
6872 |
|

|
6873 |
6873 |
|
|
6874 |
6874 |
We could also have used a combination of both!
|
We could also have used a combination of both!
|
6875 |
6875 |
|
|
|
... |
... |
SHOP(Name (PK), StreetName, Citiy, Zip) |
6902 |
6902 |
LABEL(Name (PK), Phone, LogoName, LogoColor)
|
LABEL(Name (PK), Phone, LogoName, LogoColor)
|
6903 |
6903 |
SELL(Recording (FK, PK to RECORDING.Title), Shop (PK, FK to SHOP.Name), NumberOfCopies)
|
SELL(Recording (FK, PK to RECORDING.Title), Shop (PK, FK to SHOP.Name), NumberOfCopies)
|
6904 |
6904 |
LABELGENRE(Label (PK, FK to LABEL.Name), Genre (PK))
|
LABELGENRE(Label (PK, FK to LABEL.Name), Genre (PK))
|
6905 |
|
](fig/rel_mod/RECORD)\
|
|
|
6905 |
|
](fig/rel_mod/record)\
|
6906 |
6906 |
|
|
6907 |
6907 |
---
|
---
|
6908 |
6908 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:schedule) |
6968 |
6968 |
|
|
6969 |
6969 |
Once normalized to the third normal form, we get:
|
Once normalized to the third normal form, we get:
|
6970 |
6970 |
|
|
6971 |
|
{width=90%}
|
|
|
6971 |
|
{width=90%}
|
6972 |
6972 |
|
|
6973 |
6973 |
|
|
6974 |
6974 |
---
|
---
|
|
... |
... |
Solution to [%D %n (%T)](#problem:carinfo) |
7123 |
7123 |
PERSON(ID (PK), Name, Street, City, Seat (FK to CAR.Vin), Position)
|
PERSON(ID (PK), Name, Street, City, Seat (FK to CAR.Vin), Position)
|
7124 |
7124 |
CAR(Vin (PK), Make, Year, Brand, Driver (FK to PERSON.ID))
|
CAR(Vin (PK), Make, Year, Brand, Driver (FK to PERSON.ID))
|
7125 |
7125 |
CAR INSURANCE(Insured Car (PK, FK to CAR.Vin), Policy Number (PK), Covered Amount, Company Name)
|
CAR INSURANCE(Insured Car (PK, FK to CAR.Vin), Policy Number (PK), Covered Amount, Company Name)
|
7126 |
|
](fig/rel_mod/CAR_INFO)
|
|
|
7126 |
|
](fig/rel_mod/car_info)
|
7127 |
7127 |
\
|
\
|
7128 |
7128 |
|
|
7129 |
7129 |
Note that, during the coversion, we had to make "Insured Car" part of the primary key of CAR INSURANCE.
|
Note that, during the coversion, we had to make "Insured Car" part of the primary key of CAR INSURANCE.
|
|
... |
... |
Solution to [%D %n (%T)](#problem:library_network) |
7137 |
7137 |
|
|
7138 |
7138 |
For the ER diagram, we could get something like:
|
For the ER diagram, we could get something like:
|
7139 |
7139 |
|
|
7140 |
|

|
|
|
7140 |
|

|
7141 |
7141 |
|
|
7142 |
7142 |
Note that:
|
Note that:
|
7143 |
7143 |
|
|
|
... |
... |
Solution to [%D %n (%T)](#problem:library_network) |
7157 |
7157 |
BORROWING(Copy (PK, FK to COPY.Code), Patron (PK, FK to PATRON.CardNumber), ReturnDate)
|
BORROWING(Copy (PK, FK to COPY.Code), Patron (PK, FK to PATRON.CardNumber), ReturnDate)
|
7158 |
7158 |
PATRON(CardNumber (PK), Name, Email)
|
PATRON(CardNumber (PK), Name, Email)
|
7159 |
7159 |
HOLD(Copy (PK, FK to COPY.Code), Patron (PK, FK to PATRON.CardNumber), ExpirationDate)
|
HOLD(Copy (PK, FK to COPY.Code), Patron (PK, FK to PATRON.CardNumber), ExpirationDate)
|
7160 |
|
](fig/rel_mod/NETWORK_LIBRARY)
|
|
|
7160 |
|
](fig/rel_mod/network_library)
|
7161 |
7161 |
\
|
\
|
7162 |
7162 |
|
|
7163 |
7163 |
Note that:
|
Note that:
|
|
... |
... |
Solution to [%D %n (%T)](#problem:xmltoercustomer) |
8635 |
8635 |
|
|
8636 |
8636 |
Put together, this gives the following diagram:
|
Put together, this gives the following diagram:
|
8637 |
8637 |
|
|
8638 |
|

|
|
|
8638 |
|

|
8639 |
8639 |
\
|
\
|
8640 |
8640 |
|
|
8641 |
8641 |
We made further assumptions: an order cannot be empty (transcribed by the total constraint on CONTAINS), an order does not exist if it was not passed by a customer (transcribed by the fact that ORDER is a weak entity), which also implies that an order cannot be passed by more than one customer.
|
We made further assumptions: an order cannot be empty (transcribed by the total constraint on CONTAINS), an order does not exist if it was not passed by a customer (transcribed by the fact that ORDER is a weak entity), which also implies that an order cannot be passed by more than one customer.
|
|
... |
... |
Solution to [%D %n (%T)](#problem:xmltoeraward) |
8669 |
8669 |
|
|
8670 |
8670 |
All together, this gives the following diagram:
|
All together, this gives the following diagram:
|
8671 |
8671 |
|
|
8672 |
|

|
|
|
8672 |
|

|
8673 |
8673 |
\
|
\
|
8674 |
8674 |
|
|
8675 |
8675 |
|
|