0% found this document useful (0 votes)
20 views10 pages

2022-10-21 Assignemts Normalization Implementation Solutions

Here is an ER diagram that models the resource planning for the airline DB-Air based on the given requirements: [ER DIAGRAM] Technical_Employee - ID - Name Pilot - Flight_Experience Maintenance_Technician Airline_Type - Type_Name Pilot_License - Pilot_ID - Airline_Type_ID 3. The airline operates different airplane types. For each type the maximum take-off weight and capacity is stored. 4. A flight is operated by one pilot and has a scheduled departure and arrival airport and time. It is operated with one airplane of a specific type. 5.

Uploaded by

Void Seeker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views10 pages

2022-10-21 Assignemts Normalization Implementation Solutions

Here is an ER diagram that models the resource planning for the airline DB-Air based on the given requirements: [ER DIAGRAM] Technical_Employee - ID - Name Pilot - Flight_Experience Maintenance_Technician Airline_Type - Type_Name Pilot_License - Pilot_ID - Airline_Type_ID 3. The airline operates different airplane types. For each type the maximum take-off weight and capacity is stored. 4. A flight is operated by one pilot and has a scheduled departure and arrival airport and time. It is operated with one airplane of a specific type. 5.

Uploaded by

Void Seeker
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Normalization / Scheme mapping October 21st 2022

Exercise 1: table memtra in database SportsClub

Add the column “age” as generated column to your members’ table.

 Does it need to be a virtual or a stored column? Why?


 Note down the ALTER statement
virtual

ALTER TABLE memtra


ADD COLUMN `age` INT
GENERATED ALWAYS AS (timestampdiff(YEAR,`DoB`,curdate()) ) VIRTUAL

AFTER `DoB`;

Why does it have to be a generated virtual column and not a generated stored column?

Virtual: Dynamic generation when a row is queried / stored: evaluation on inserts and
updates – would not work with age.

Exercise 2:

Map the Internet Forum ER model into the corresponding relations’ scheme. Underline PKs
and mark FKs. Note, which FKs need a unique index and which must not have a unique index.

How would you map the attribute country? - as lookup table

How many final relations do you get? - 6

Feel free to implement DB.


Internet Forum

country: {[countryCode:string, countryName:string]}

user: {[userName:string, email:string, isModerator:Boolean, userDescription:text,


countryCode:char]} fk countryCode not unique

forum: {[fID:int, fTitle;string, fDescription:sting, moderator:string]} – FK index unique

post: {[ fID:int, postID:int, postTitle:string, wDate:date, content: string, refForum:int,


refPost:int, userName:string]} – fkrefForum/refPost – not unique, fk username -not
unique

fRegistration: {[fID:int, username:string, rDate:date]} – fks not unique

pLikes: {[fID:int, postID:int, userName:string, lDate:date]} – fks not unique

Exercise 3: Follow-Up Question:


What is the difference between the implementation of

1) a weak entity and its parent strong entity and


2) the implementation of two entities with a 1:N relation?

How many relations with what keys are created in each case?

In both cases 2 entity relations are created.


Case 1) strong - weak entity: a column with the primary key of the strong entity is added to
the relation of the weak entity. This column is at the same time foreign key and part of the
primary key. That means: it cannot be NULL at any time. (Total participation)

Case 2) 1:N: A column with the foreign key to the primary key of the relation belonging to
the 1-side is added to the relation belonging to the N-side. It may be a partial participation.

Difference in implementation: In strong-weak entity case the PK of the strong entity is part
of the PK of the weak entity and FK at the same time and in the other case only a FK is
created.

Exercise 4: Normalization:

article_ article_ price storage stock supplier telephone


ID description location supplier

1 skis 200 Vienna 50 A 123456

1 skis 200 Munich 25 B 234567

2 tent 150 Berlin 10 C 345678

3 snowshoes 100 Berlin 50 A 123456

4 boots 50 Vienna 150 A 123456

4 boots 50 Cologne 5 A 123456

4 boots 50 Munich 15 B 234567

4 boots 50 Munich 5 D 589944

1. In which normal form is the relation?

1st normal form

2. Identify partial and full FDs

{articleID.} {articleDescription, Price} – partial dependency

{articleID,storgaeLoc,supplier}  {stock} – full dependency


{supplier}  {supplierTelephon} – partial dependency

3. Transform relation into 3rd normal form.


supplier telephone
article_ article_ price
supplier
ID description

A 123456
1 skis 200

B 234567
2 tent 150
C 345678
3 snowshoes 100
D 589944
4 boots 50

article_ storage supplier stock


ID location

1 Vienna A 50

1 Munich B 25

2 Berlin C 10

3 Berlin A 50

4 Vienna A 150

4 Cologne A 5

4 Munich B 15

4 Munich D 5

storageLoc street postalCode

Berlin

Cologne

Munich
Vienna

4. Does 3rd NF also fulfill BCNF?


Yes – no candidate keys. Just one composite key.

5. Do some reverse engineering and draw a well designed ER-model out of your relations.

Exercise 5: BCNF / Normalization

A) The following table empProject keeps track of which employee works on what
projects in what function. Of each employee, the relation stores the social security
number and the employee ID. Employees can work on different projects and can
have a different function in each project they work on. The table also keeps track of
the date that an employee started to work on the project.

EmpProject

SSN Emp_ID Function Project startDate


ProjectManage
01136 1 ERP 2020-01-01
r
74589 2 Developer ERP 2020-10-01
ProjectManage
55587 3 Portal 2019-10-01
r
12345 4 Tester CRM 2021-02-01
12345 4 Developer Portal 2019-11-01
12345 4 Tester Linux 2021-01-01

1. What is the key or what are the candidate keys?


2. Which FDs exist?
3. In what normal form is the relation?
4. Transform the relation into BCNF. Can you preserve all FDs while decomposing?

1. Candiate keys: {SSN, Project} or [Emp_ID,project}


2. FDs:

SSN  Emp_ID,
Emp_ID  SSN
{SSN, Project}  function, startDate
{Emp_ID,project}  function, startDate

3. 3rd NF

4. Yes, dependencies can be preserved

R1: {Emp_ID ,SSN}


R2: {Emp_ID, project, function, startDate}
OR:

R1: {SSN, Emp_ID}


R2: {SSN, Project, function, startDate}

B) Georgian Version: An agency manages in its database IT Freelance people that work
for different companies on different projects.

CompanyNa
SSN CompanyID Function Project startDate
me
01136 1 TBG Bank ProjectManager ERP 2020-01-01
74589 2 Bank Imereti Developer ERP 2020-10-01
55587 3 Telavi Wines ProjectManager Portal 2019-10-01
01136 4 Poti Port Tester CRM 2021-02-01
12345 4 Poti Port Developer Portal 2019-11-01
12345 4 Poti Port Tester Linux 2021-01-01
Solution 1: project name is not unique

1. What is the key of the relation? {SSN, Project, companyID}


2. What FDs exist? {SSN, Project, companyID }  {function, startDate}
{CompanyID}  {CompanyName}
3. What NF is the relation in: 1st NF (only existing partial dependency is companyName,
a non-key attribute)
4. Transform into 3rd NF / BCNF

FreelancerProjects: {[SSN, Project, companyID, function, startDate]}


Company: {CompanyID, CompanyName]}

Solution 2: projectID / name is unique

1. What is the key of the relation? {SSN, Project}


2. What FDs exist? {SSN, Project}  {companyID, function, startDate}
{CompanyID}  {CompanyName}
3. What NF is the relation in: 1st NF
4. Transform into 3rd NF / BCNF

FreelancerProjects: {[SSN, Project, companyID, function, startDate]}


Company: {CompanyID, CompanyName]}

Solution 3: CompanyID and CompanyName are unique but projectName is not unique

1. What is the key of the relation?


2 candidate keys: {SSN, CompanyID,Project}
{SSN, CompanyName, project}

2. What FDs exist? {{SSN, Project, companyID }  {function, startDate}


{CompanyID}  {CompanyName}

{{SSN, Project, companyName }  {function, startDate}


{CompanyName}  {CompanyID}
2. What NF is the relation in: 3rd NF
3. Transform into BCNF

a. FreelancerProjects: {[SSN, Project, companyID, function, startDate]}


Company: {CompanyID, CompanyName]}
b. FreelancerProjects: {[SSN, Project, companyName, function, startDate]}
Company: {CompanyName, CompanyID]}
Exercise 6: ER Model Airline Resource Planning

The airline DB-Air wants to manage their resource planning with a database. The database needs to
fulfill the following semantical requirements:

1. The database keeps track of the technical employees of the airline: For each technical employee
the database stores ID and name. Technical employees are either pilots or maintenance
technicians. The database stores the overall flight experience (in hours) that each pilot has.
2. A pilot may only fly the airline types that he / she has a license for. The database keeps track of
the date of issue of each respective license.
3. Each experienced pilot may mentor young pilots. Each young pilot may only have one mentor.
4. Each maintenance technician works in a maintenance team. Each team has an ID. One of the
technicians is the leader of the maintenance team. The database keeps track which aircraft types
a team can maintain.
5. The database keeps track of all aircrafts that the airline uses. It stores aircraft ID, aircraft name,
purchase date, date of last full maintenance, teamID of the team that carried out the last
maintenance and aircraft type.
6. The information that is stored with the aircraft type is type code, name and maximum
occupancy.
7. All airports that the airline flies to are stored with the airport code, name and country. For each
airport the database keeps track which aircraft types have a landing permission for that airport.

1. Develop the corresponding EER model, underline keys.


2. Write standard cardinalities for all relationships.
3. Add the following (min,max) cardinalities:
a. A pilot needs to be able to fly at least 3 aircraft types. Any aircraft type that the airline
uses needs to be able to be flown by at least 10 pilots.
b. At least 2 of the aircraft types that the airline uses need to be allowed to land at any
airport that the airline flies to. Each aircraft type that the airline uses needs to be allowed
to land at at least 50 airports that the airline flies to.
c. A pilot may have up to 5 mentees. A young pilot does not need to have a mentor.
d. Each maintenance team consists of exactly 5 technicians, including the leader. Each
technician belongs to exactly one maintenance team.
Expected Result Points

Correct entities (aircraft, aircraftType, maintenanceTeam, airport), minus if there are more 2
entities that do not make sense / do not have attributes / are not needed.

Correct disjunct specialization / generalization (total and partial are both correct): technical 1
employee – pilot – technician.

Correct relationships between entitites 1

Correct recursive relationship 1

Attributes directly at relationships (last MainDate, DateIssueLicense) 1

Keys – identifies and underlined, no keys for subtypes 2


Standard cardinalities correct 4

(min,max) cardinalities correct 2

Bonus point: country as separate reference table (does not need to be extra in EER.) (1)

Total (without bonus point) 14

You might also like