© Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.
-
Upload
garry-jennings -
Category
Documents
-
view
218 -
download
0
Transcript of © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.
![Page 1: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/1.jpg)
© Jalal Kawash 2010
2 Databases &Data Modelling
Peeking into Computer Science
![Page 2: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/2.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Reading Assignment
Mandatory: Chapter 4 – Sections 4.4 & 4.5
2
![Page 3: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/3.jpg)
Mapping ERDs to Schema
3
![Page 4: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/4.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Objectives
At the end of this section, you will be able to:
1. Apply the mapping algorithm to translate an ERD to a database schema
2. Understand foreign keys
![Page 5: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/5.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Mapping Algorithm (4.1)
1. Each entity type is translated to a table; its attributes become columns
2. Each many-to-many relationship type becomes a table; the columns are the primary keys of the participating entity types JT: Recall the example from previous notes (Slide #38):
Student-Classes
3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side
5
![Page 6: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/6.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Mapping Entity Types
1. Each entity type is translated to a table; its attributes become columns
6
![Page 7: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/7.jpg)
© Jalal Kawash 2009Peeking into Computer Science 7
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
![Page 8: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/8.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra:8
The actual tables in a database
Entities (conceptual information to be stored)
![Page 9: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/9.jpg)
© Jalal Kawash 2009Peeking into Computer Science
JT’s Extra: Recall Many : Many Relations Can’t Be Directly Implemented
![Page 10: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/10.jpg)
© Jalal Kawash 2009Peeking into Computer Science
JT’s Extra
Mapping Many-Many Relationship Types
2. Each many-to-many relationship type becomes a table; the columns are the primary keys of the participating entity types
10
![Page 11: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/11.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Participation Levels11
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
![Page 12: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/12.jpg)
© Jalal Kawash 2010Peeking into Computer Science
There will be no more tablesStep 3 simply augments the existing
tables (JT’s extra i.e., you add more columns).
![Page 13: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/13.jpg)
© Jalal Kawash 2009Peeking into Computer Science
There will be no more tablesStep 3 simply augments the existing
tables
JT’s Extra: (In case you missed it in Jalal’s example)
![Page 14: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/14.jpg)
© Jalal Kawash 2009Peeking into Computer Science
Mapping One-Many Relationship Types
3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side
14
![Page 15: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/15.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: Foreign Keys
A key in one table that refers to a key in another field.
![Page 16: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/16.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Mapping One-Many Relationship Types
3. For each one-to-many relationship type, add the primary keys of the entity type on the one side as columns in the table corresponding to the entity type on the many side
16
JT’s Extra
Table 1 Table 21
ManyPrimary key
Primary key
Foreign key
![Page 17: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/17.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: Mapping 1:Many17
• The relationship between Department and Employee is 1 to many.
• The primary of Department table (“One side”)
• …becomes a column in the Employee table (“Many side”).
![Page 18: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/18.jpg)
© Jalal Kawash 2009Peeking into Computer Science 18
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
Dnumber tells us which Department an employee works for
Dnumber is a foreign Key
![Page 19: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/19.jpg)
© Jalal Kawash 2009Peeking into Computer Science 19
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
![Page 20: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/20.jpg)
© Jalal Kawash 2009Peeking into Computer Science 20
![Page 21: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/21.jpg)
© Jalal Kawash 2009Peeking into Computer Science 21
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
Dnumber
![Page 22: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/22.jpg)
© Jalal Kawash 2009Peeking into Computer Science 22
![Page 23: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/23.jpg)
© Jalal Kawash 2009Peeking into Computer Science
The Complete Schema
![Page 24: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/24.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Two Missing Things
The mapping algorithm does not include one-to-one relationship types◦We need to include these
Sometimes, relationship types may need to have their own attributes
Will revise ERDs and the mapping algorithm to include these.
24
![Page 25: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/25.jpg)
© Jalal Kawash 2010Peeking into Computer Science
MANAGES Relationship Type
A department is managed by one employee
Each department has a manager which is also an
employee
EMPLOYEE and DEPARTMENT are related by the
MANAGES relationship type
Each department can have only one manager,
and each employee can manage at most one
department. This is a one-to-one relationship
25
![Page 26: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/26.jpg)
© Jalal Kawash 2009Peeking into Computer Science
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
MANAGES
![Page 27: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/27.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Attributes for Relationship types27
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
MANAGES
- Hours
- Start date
JT: explanation for ‘source data’ and ‘hours’ coming shortly
![Page 28: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/28.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: Notation Reminder
Entity (object in real world): E
Table (in database): T
Table (in database): T
Table (in database): T
Relationship: R
Entity: E
Entity: E
![Page 29: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/29.jpg)
© Jalal Kawash 2010Peeking into Computer ScienceComplete mapping Algorithm
1. Each entity type E is translated to a table T (to emphasize that T is a result of E, we write T(E))
◦ T’s columns are E’s attributes
2. Each many-to-many relationship type R, relating entity types E1 and E2, becomes a table T (relationship becomes a table)
◦ T’s columns are R’s attributes◦ the primary key of E1 and E2 is added as
columns in T
29
Entity (DOG) attributesColor (Rover = yellow)Weight (Rover = 5 llbs)
Name Color Weight
Rover Yellow 5
Database Table (DOGS)
![Page 30: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/30.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Complete mapping Algorithm
3. For each one-to-many relationship type R, relating E1 to E2 with E1 on the “one” side:
◦ add the primary key of E1 (one) as a column or columns in T(E2)
◦ any attributes that R has become columns in T(E2)
30
![Page 31: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/31.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: 1 to 1 Relationships
To ensure compliance with good design principles, examine participation levels when determining which table’s primary key is used as the other table’s foreign key.◦If both tables participate equally (both partial
or both full) then the choice is arbitrary.
T1 T2 T1 T2OR
![Page 32: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/32.jpg)
© Jalal Kawash 2010Peeking into Computer Science
◦If participation levels aren’t equal: If one table partially participates in the relationship while the other table participates partially in the relationship.
JT’s Extra: 1 to 1 Relationships (2)
Table 2Table 1Primary key Foreign key
Full
Partial
![Page 33: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/33.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Complete mapping Algorithm
4. For each one-to-one relationship type R, relating E1 to E2 with E1 on a partial participation side or both E1 and E2 fully participate in R:
◦ add the primary key of E1 (JT: partial) as a column or columns in T(E2, JT: full)
◦ any attributes that R has become columns in T(E2)
33
![Page 34: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/34.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: Attributes Of Relationships
Employee
Project
Works on
Many
Many
Hours?
Hours?
Hours!
![Page 35: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/35.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra: Attributes Of Relationships (2)
EmployeeDepartment
ManagesOne
Many
Works for
One
Many
Start date?
One
Start date!
Start date?
![Page 36: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/36.jpg)
© Jalal Kawash 2009Peeking into Computer Science 36
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
MANAGES
- Hours
- Start date
![Page 37: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/37.jpg)
© Jalal Kawash 2009Peeking into Computer Science 37
EMPLOYEE- SIN
- First name- Last name
- DOB- Gender- Salary
- Number- Street- City
- Postal Code
DEPARTMENT
- Number- Name
PROJECT
- Number- Name
- Location
CONTROLS
WORKS ON
WORKS FOR
MANAGES
- Hours
- Start date
![Page 38: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/38.jpg)
© Jalal Kawash 2009Peeking into Computer Science
The Complete Schema
![Page 39: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/39.jpg)
Design PrinciplesWhat makes a Good Design?
39
![Page 40: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/40.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Objectives
At the end of this section, you will be able to:
1. List and entertain the three basic design principles
2. Understand how our mapping algorithm satisfies these three principles
![Page 41: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/41.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Basic Design Principles
1. Meaning of a Schema should be easily explained
2. Reduce Redundancy
3. Reduce NULL values
41
![Page 42: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/42.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Design Principle (1)
1. Design a schema so that its meaning can be easily explained
Do NOT combine attributes from different entity types into a single table
42
![Page 43: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/43.jpg)
© Jalal Kawash 2010Peeking into Computer Science
A schema with no clear meaning
Project, department, or controls table?◦JT: what is the collective info stored, it’s a
smattering of unrelated attributes.
![Page 44: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/44.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Design Principle (2)
2. Design a schema so that Redundancy is reduced
Unnecessary Redundancy can lead to modification anomalies
44
![Page 45: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/45.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT: Recall Department And Project45
1
Many
With 1:Many relationship the primary key of the ‘1’ became foreign key on the ‘many’ side
![Page 46: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/46.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Unnecessary Redundancy
Assume the schema definition for Project and Department ◦migrating Pnumber to DEPARTMENT
46
![Page 47: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/47.jpg)
© Jalal Kawash 2009Peeking into Computer Science 47
4
More than one place to change IT
![Page 48: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/48.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Modification Anomaly Example
ABC company decides to change the name of IT department to Technology
48
![Page 49: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/49.jpg)
© Jalal Kawash 2010Peeking into Computer Science
No Anomalies Here49
The only place to change IT
![Page 50: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/50.jpg)
© Jalal Kawash 2009Peeking into Computer Science 50
Must change all occurrences of IT here and
elsewhere
IT occurs in more than one place
![Page 51: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/51.jpg)
© Jalal Kawash 2009Peeking into Computer Science
JT’s Extra: Null Values
Refers to empty fields of a record.Primary keys cannot be null but other fields may be null.
![Page 52: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/52.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Design Principle (3)
3. Design a schema so that NULL values are minimized as much as possible
Waste space Result in confusion:
◦ A NULL value could mean: Does not apply Unknown To be recorded
52
![Page 53: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/53.jpg)
© Jalal Kawash 2010Peeking into Computer Science
NULL Values Confusion
NULL
NULL
1. Arrangement to work until completion
2. We do not know the hours yet
3. Someone else will enter it (it is known)
![Page 54: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/54.jpg)
© Jalal Kawash 2010Peeking into Computer Science
NULL Values Example
We migrated the managers SIN (partial participation side) to the DEPARTMENT table (full participation side)◦JT: this is what we should do
54
![Page 55: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/55.jpg)
© Jalal Kawash 2010Peeking into Computer Science
NULL Values Example
What if we migrated the department Number to the EMPLOYEE table?◦JT: again this is what should be done (1:many,
primary key of ‘one’ becomes foreign key of many)
55
![Page 56: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/56.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Original Design56
![Page 57: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/57.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT: Manager Info (Manager ‘Manages’ A Department)
57
![Page 58: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/58.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT: What If Manager Info Stored Elsewhere?
Manager info stored in ‘employees’ table rather than department table.
58
![Page 59: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/59.jpg)
© Jalal Kawash 2010Peeking into Computer Science
Alternative Design59
JT’s Extra: zoom
![Page 60: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/60.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra (Null): Many to many relationships: directly modeled in a database.
60
StudentID StudentFirstName StudentLastName
123456 Jamie Smyth
123457 Stacey Walls
123458 Angel Lam
ClassName
ClassNumber Lecture No ClassDescription
CPSC 203 01 Introduction to Computers
CPSC 231 01 Introduction to Computer Science I
CPSC 233 01 Introduction to Computer Science II
Students table
Classes table
![Page 61: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/61.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra (Null): Many to many relationships: directly modeled in a database.
61
StudentID StudentFirstName
StudentLastName
123456 Jamie Smyth
123457 Stacey Walls
123458 Angel Lam
Students table
Class 1
Class 2
Class 3
Class 4
Class 5
… Class ‘N’
CPSC 203
PSYC 205
MATH 221
MATH 251
SOCI 201
NULL
CPSC 203
ART 201
MATH 271
NULL NULL NULL
CPSC 203
CHIN 201
KINE 221
MGIS 323
OPMA 341
NULL
![Page 62: © Jalal Kawash 2010 2 Databases & Data Modelling Peeking into Computer Science.](https://reader036.fdocuments.in/reader036/viewer/2022062423/56649ea95503460f94bacaba/html5/thumbnails/62.jpg)
© Jalal Kawash 2010Peeking into Computer Science
JT’s Extra (Null): Many to many relationships: directly modeled in a database.
62
ClassName
ClassNumber
Lecture No ClassDescription
CPSC 203 01 Introduction to Computers
CPSC 231 01 Introduction to Computer Science I
CPSC 233 01 Introduction to Computer Science II
Classes table
S1 S2 S3 S4 S5S6 S7 … SN
Bill Bob Mary Jane NULL NULL NULL NULL
Jim NULL NULL NULL NULL NULL NULL NULL
Alice Brett Charlie
Deacon
Ernie Edgar Freda NULL