07-Data Modeling
07-Data Modeling
Data Modeling
Data Model
Project Specific
Some slides extracted from IBM coursewares Guidelines Design Model
1 2
3 4
4. Normalization
3 4
1
5 6
5 6
7 8
7 8
2
9 10
9 10
11 12
11 12
3
14
13 14
15 16
15 16
4
17 18
17 18
19 20
19 20
5
21 22
21 22
23 24
products
ORDER LINE ITEM
Order_Id LineItem_Id
lineItems
Software Product Hardware Product Description
Price PRODUCT
- version : Double - assembly : String
Quantity
lineItem order
Product_Id Product_Id
Order_Id Name
Price
Columns
23 24
6
25 26
25 26
27 28
27 28
7
29 30
1. Data models
- number : Integer
+order 1..*
- number : Integer • Map persistent design
1 classes to Entities
2. Object model and Rational Data Model Product
- number : Integer
- description : String • Map class relationships to
- unitPrice : Double
products
ORDER LINE ITEM
Order_Id LineItem_Id
lineItems
Description
Price PRODUCT
Quantity
lineItem order Product_Id
Product_Id
Order_Id Name
Price
Columns
29 30
31 32
31 32
8
33 34
33 34
35 36
More example in Course Registration 3.4. Modeling Inheritance in the Data Model
1
• Duplicate all inherited associations and attributes (de-
Foreign Key Schedule entity
normalized data)
Schedule
scheduleI courseID day teachingPerio
-scheduleID: int D d
0.* -day: String
-teachingPeriod: int 1 IT3598002 Tuesda 2
y
2 IT3598002 Tuesda 3
y
1 IT3672001 Friday 8
35 36
9
37
UserInfo UserInfo
- userID: String - userID: String
User entity
Student entity
userID userName email phoneNumber address
studentID studentName email phoneNumber address
2005.03229 Nguyễn Hoàng student_200503229@ 0988.394.394 No. 12, …
2005.03229 Nguyễn Hoàng student_200503229@ 0988.394.394 No. 12, …
hut.edu.vn
hut.edu.vn
002.005.00060 Trần Nam Khánh [email protected] 0912.473.568 No. 157, …
Replication
Primary Key Lecturer entity
Lecturer entity
lecturerID lecturerName email phoneNumber address eduBackground
lecturerID eduBackground
002.005.00060 Trần Nam Khánh khanhtn@ 0912.473.568 No. 157, Master from HUT…
Primary Key 002.005.00060 Master from HUT… hut.edu.vn …
38
37 38
40
C
C_ID
A_ID (FK)
0..3
A B_ID (FK)
A_ID c_attr_1
A * * B c_attr_2
A_ID B_ID
SubjectInfo Prerequisite
prerequisiteID
subjectID subjectID
C
B subjectName prerequisiteSubjectID
c_attr_1 level
c_attr_2 B_ID numberOfCredit
decription
39
39 40
10
42
Schedule
«column»
CourseRegistration
«column»
Course
*PK scheduleID
*PK courseID
day
1. Data models
*PK courseID «column» teachingPeriod
*PK studentID
studentName
registeredDate
*PK courseID
subjectID
description
«PK» 2. Object model and Rational Data Model
Dependency + PK_Schedule(, )
startDate
Subj ect
«PK»
+ PK_Course()
StudyHistory
«column»
4. Normalization
*PK historyNo
«column»
courseID
*PK subjectID
studentID
subjectName
studentName
goal
result
numberOfCredit
pass
description Prerequisite
«column» «PK»
«PK»
*PK prerequisiteID + PK_StudyHistory()
+ PK_Subject()
* subjectID
prerequisiteSubjectID
level
description
«PK»
41 + PK_Prerequisite()
41 42
43 44
43 44
11
45 46
45 46
47 48
47 48
12
49 50
49 50
51 52
51 52
13
53 54
53 54
55 56
55 56
14
57 58
• 1NF:
2NF {Order, Product, Customer, Address, Quantity, UnitPrice}
R1 Order Customer Address
• 2NF:
{Order, Customer, Address}
{Product, UnitPrice}
{Order, Product, Quantity}
• 3NF:
3NF {Product, UnitPrice}
{Order, Product, Quantity}
R5 Order Customer R6 Customer Address {Order, Customer}
{Customer, Address}
57 58
59 60
0NF 3NF
Prices Product UnitPrice
59 60
15
dm E-R Modeling
61 62 Schedule
«column»
CourseRegistration *PK scheduleID
«PK»
+ PK_Prerequisite()
1NF
61 62
1NF 63
dm Normalization 2
2NF 64
dm Normalization 1
Schedule
CourseRegistration Course
Schedule
CourseRegistration Course «column»
«column» «column»
«column» *PK scheduleID
*PK courseID
«column» «column» *PK scheduleID
*PK courseID day
* subjectID
*PK courseID *PK courseID *PK courseID
*PK studentID teachingPeriod
registeredDate description
*PK studentID subjectID day
courseID
startDate
studentName description teachingPeriod endDate
registeredDate startDate «PK» «PK»
location
endDate + PK_CourseRegistration(, ) + PK_Schedule()
«PK» lecturerID
location StudyHistory
«PK» lecturerID + PK_Schedule(, )
+ PK_CourseRegistration(, ) StudyHistory «PK»
«column»
+ PK_Course()
«PK» «column»
*PK historyNo
+ PK_Course() studentID
*PK historyNo
Student studentName
Subj ect courseID
result
studentID pass
«column»
«column» studentName
*PK studentID courseID
*PK subjectID result
studentName
subjectName pass
phone «PK»
goal Prerequisite
address + PK_StudyHistory()
numberOfCredit
Prerequisite «PK» email
description + PK_StudyHistory() «column»
Lecturer
*PK subjectID Lecturer
«column» «PK» Subj ect
«PK» *PK prerequisiteID «column» + PK_Student()
*PK prerequisiteID
level «column» «column»
+ PK_Subject() * subjectID *PK lecturerID
description *PK subjectID *PK lecturerID
prerequisiteSubjectID lecturerName
subjectName lecturerName
level educationalBackground educationalBackground
«PK» goal
description phone phone
+ PK_Prerequisite(, ) numberOfCredit
email email
description
«PK» address address
+ PK_Prerequisite() «PK»
«PK» «PK»
+ PK_Subject()
+ PK_Lecturer() + PK_Lecturer()
63 64
16
3NF 65 66
dm Normalization 3
CourseRegistration Course
Schedule
«column»
Question?
«column» «column»
*PK scheduleID
*PK courseID *PK courseID
*PK courseID
*PK studentID subjectID day
registeredDate description teachingPeriod
startDate
endDate
«PK» «PK»
location
+ PK_CourseRegistration(, ) + PK_Schedule(, )
lecturerID
StudyHistory
«PK»
«column»
+ PK_Course()
*PK historyNo
courseID
Student studentID
result
«column» pass
*PK studentID
studentName «PK»
phone + PK_StudyHistory()
address Prerequisite
email
«column»
*PK prerequisiteID Subj ect Lecturer
«PK»
* subjectID
+ PK_Student() «column»
prerequisiteSubjectID «column»
level *PK subjectID *PK lecturerID
description subjectName lecturerName
goal educationalBackground
numberOfCredit phone
«PK»
description email
+ PK_Prerequisite()
address
«PK»
+ PK_Subject() «PK»
+ PK_Lecturer()
65 66
17