National University of Modern Languages - NUML: (Department of Computer Science)
National University of Modern Languages - NUML: (Department of Computer Science)
National University of Modern Languages - NUML: (Department of Computer Science)
Languages - NUML
(Department of Computer Science)
Mr. Muhammad Nouman Farooq
BSC-H (Computer Science)
MS (Telecomm. and Networks)
Honors:
Magna Cumm Laude Honors Degree
Gold Medalist!
Data Modeling
Lecture#4
2
Lecture 4: Data Modeling
Data Dictionary
4
Data Modeling
1. Business Rule
5
Database Design/Data Modeling
6
Continued...
Top-Down Approach: -
Design by Analysis
Only Database Administrator’s can firstly design the
structure of the database (makes an ERD in Conceptual Data Modeling
Phase) and than transforms it into Relations in Logical Data Modeling
Phase and than afterwards code that structure of transformed ERD in
Implementation Phase using a DBMS (MySQL in XAMPP) making a
Database System; This approach is termed as Design by Analysis. A
good design must reduces duplication of data, reduces anomalies in
data, we must makes it in 3rd Normal Form (3-NF) for commercial
applications.
In Physical Design phase; It requires a knowledge of the
specific DBMS that will be used to implement the database (data
types, triggers, indexes etc).
Bottom-Up Approach: -
Design by Synthesis 7
Database Modeling
8
Continued...
9
A GOOD Business Rule Is:
10
Business Rules
11
CLASS EXERCISE (ERD Reading as per Business Rule)
12
SOLUTION OF CLASS EXCERCISE
13
ERD Reading
1. A STUDENT may be assigned to some POST like Monitor,
Perfect, and each POST must be responsible by at most one
STUDENT.
18
Standard used for Database System Designing
Tools/Simulator can also help the designer and the user to mutually
agree on a specific design.
19
Continued…
20
E-R Model Constructs
21
Components of ER Diagram
The ER data model supports following major constructs:
1. The Entity
2. Attribute
3. Relationship
22
The Entity
1. Entity Type
2. Entity Instance
3. Entity Set
23
Entity Type
24
Continued…
25
Classification Of Entity Types
Entity types (ETs) can be classified into regular ETs or weak ETs.
26
Weak Entity Types
It depend on some other entity type and have no meaning in the diagram
without depending on another entity.
Example: Course (Course cannot be taught without teacher)
An entity type whose instances cannot exist without being linked with
instances of some other entity type, i.e., they cannot exist independently.
Now, a particular vehicle can exist in this organization only if the owner
already exists there as employee.
27
Continued…
28
Strong Entity Types
A major property of the strong entity types is that they have their
own identification, which is not always the case with weak entity
types.
29
Entity Instance
Each entity instance possesses certain values against the properties with
the entity type to which it belongs.
For example, In the given table on next slide; we have identified that
entity type EMPLOYEE has name, father name, registration number,
qualification, designation.
Now, an instance of this entity type will have values against each of these
properties, like (M. Sajjad, Abdul Rehman, EN-14289, BCS, and
Programmer) may be one instance of entity type EMPLOYEE. There could
be many others.
30
Continued…
31
Continued…
32
Entity Set
33
Naming Entity Types
3. Write in Capitals
For strong entity types rectangle with a single line is used whereas
double lined rectangle is drawn to represent a weak entity type as is
shown below:
35
Attribute
36
Continued…
However, different entity types may have attributes with the same name.
37
Continued…
Standard of writing Attributes is:
39
Continued…
Associating domain with an attribute helps in maintaining the
integrity of the database, Since only legal values could be
assigned to an attribute.
40
Continued…
Not only specify that the value of salary will be numeric but also
associated with a range, a lower and upper limit. It reduces the
chances of mistake.
41
Continued…
Another important thing is that once we associate a domain to
an attribute, all the attributes in all entity instances of that
entity type will have the values from the same domain. For
example, it is not possible that in one entity instance the
attribute salary has a value 15325.40 and in another instance the
same attribute has a value 15325.
All attribute will have values from same domain, values may be
different or same, whatever, but the domain will be the same.
42
Types of Attributes
Attributes may be of different types. They may be:
1. Simple or Composite
3. Stored or Derived
4. Key or Non-Key
5. Required or Optional
43
Simple or Composite
45
Stored or Derived Attributes
Normally attributes are stored attributes, that is, their values are
stored and accessed from the database.
However, sometimes attributes values are not stored, rather they are
computed or derived based on some other value. For example, we
may store the name, father name, address of employees, but age can
be computed from date of birth.
1. empFirstName
2. empLastName
3. empIdNo
4. empHobbies
5. empPassword
47
Solution of Class Activity (Classification of Attributes)
1. empFirstName –
Simple, Required, Stored, Non Key, Single Valued
2. empLastName –
Simple, Optional, Stored, Non Key, Single Valued
3. empIdNo –
Key, Simple, Required, Stored, Single Valued
4. empHobbies –
Simple, Optional, Stored, Non Key, Multi Valued
5. empPassword –
Simple, Required, Stored, Non Key, Single Valued
48
Symbols for Attributes (Standard of
Designing Attributes)
49
50
Relationships
Relationships, which represent the link between different entities.
Each relationship has a Degree (how many entity types which are
participating in a relationship for example Unary, Binary and ternary)
51
Symbol for Relationships
1. Shown as a Diamond.
53
Crow’s Foot ERD-Relationship Representation 2
54
Naming Relationships
55
Continued…
STUDENT and CLASS have enrolled relationship. However, it can also
be named as STD_CLS.
56
Relationships Instances
57
Types of Relationships
One-to-One − When only one instance of an entity is associated with the relationship,
it is marked as '1:1'.
Any Example??
EMPLOYEE to PARKING_PLACE??
E.g. an EMPLOYEE must be assigned to one and only one PARKING_PLACE, and each
PARKING_PLACE must be assigned to only one EMPLOYEE
58
Continued…
One-to-Many- When more than one instance of an entity is associated with a
relationship, it is marked as '1:N'.
Any Example??
Any Example??
E.g. STUDENT must be taught by at most one TEACHER. TEACHER must teaches
at least five number of STUDENT.
60
Continued…
Many-to-Many- The following image reflects that more than one instance of an
entity on the left and more than one instance of an entity on the right can be
associated with the relationship.
Any Example???
E.g. STUDENT may completes one or more than one COURSE, and each COURSE
may be completed by many number of STUDENT
61
Continued…
62
Degree of a Relationship
63
Continued…
64
Continued…
65
Continued…
66
n-ary Relationships
67
Cardinality of Relationship
68
Relationship Cardinalities
69
Continued…
70
Continued…
71
Continued…
72
Type of Relationship and Cardinality in a Relationship
73
ERD reading (Crow’s Foot Notation)
74
How to Create an ERD
1. Identify entities
2. Identify relationships
4. Add Attributes
75
Entities VS Relationships
76
Scenarios
77
Data Dictionary
78
Data Dictionary
79
80
Continued…
81
Continued…
82
83
Relational Schema Diagram
84
Relational Schema Diagram
It defines how the data is organized and how the relations among
them are associated.
85
Continued…
86
ERD Reading
87
Continued…
88
Continued…
89
Exercise
Draw the ERD (Information Engineering Standard) for the following
scenarios:
ii. Player plays for a at most one Cricket team, In a Cricket team at least
eleven players must play.
iii. Each patient has one or more patient histories; each instance of patient
history belongs to one patient only.
iv. An employee may be recorded as having many jobs; a particular job may
be recorded as having been held by many employees.
Type of Relationship:-
Type of relationship is One (COUNTRY) to Many (PERSON)
91
92
1)Is the scenario on last slide is in Relational Database or in Flat File System?
It is in Relational Database because two tables relates with each other with
Primary Key and Foreign Key.
93
2)Is
the designed scenario on last slide is 100% correctly designed to achieve the
core objective of Relational Database System?
94
3) If In Relational Database; Than, How it is minimizing Duplication of
Data?
95
4) Is it minimizing Update and Delete Anomaly/Irregularity?
96
1) Is the above designed scenario is in Relational Database or in Flat File
System?
It is in Relational Database because two tables relates with each other with Primary
Key and Foreign Key.
98
Case Study-1
99
Entities
Step 1: Identifying Entities: -
STUDENT
CLASS
100
Step 2: Writing Scenario with Type and Cardinality of Relationship as per
Business Rules: -
101
Reasoning for Type of Relationships: -
102
Step 3: ERD Designing in Information Engineering Style: -
103
Entities
Step 4: Transforming ERD into Relations (If Required): -
STUDENT
CLASS
104
Reasoning behind finding Type of Relationships with a Junction Table: -
105
POST Entity/Table is known as Associative or Junction Entity/Table
because it relates two number of Table’s as shown in previous diagram.
108
Entities
CINEMA
THEATER
SHOW
MOVIE
109
Relationships
A CINEMA must contain one or more THEATERs. A THEATER must
belong to only and only one CINEMA.
A MOVIE may have many SHOW times and a particular SHOW time
must belongs to one MOVIE only.
110
ERD Simulators/Tools
ERD Online Simulator: -
https://erdplus.com/#/standalone
https://www.lucidchart.com
Smart Draw
RISE Editor
Rational Rose
111
Projects Recommendation
Prediction Database System (A system which can dynamically
predict and changes record where required)
Important Note:
1.All
Projects must dynamically changes record; Based on Parent
Table’s record.
112
Recommended Readings
Chapter 3 from:
Modern Database Management-8th Edition by Jeffrey A. Hoffer,
Mary B. Prescott & Fred R. McFadden (Page No. 116-171)
Chapter 11 from:
Database Systems-A Practical Approach to Design, Implementation
and Management by Thomas Connolly and Carolyn BEGG, 4th Edition
(Page No. 393-421)
Chapter 4 from:
Database Systems - Design, Implementation, and Management by
Carlos, Steven and Peter, 9th Edition (Page No. 129-176)
113
Summary of Lecture
➦ Lecture 4
Data Dictionary
114
END OF LECTURE 4
115