0% found this document useful (0 votes)
28 views23 pages

Berl2232 Lecture W2

Uploaded by

Samz Adrian
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)
28 views23 pages

Berl2232 Lecture W2

Uploaded by

Samz Adrian
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/ 23

CHAPTER 2

DATA MODELS

Ts. Dr. Norfadzlia Binti Mohd Yusof


Jabatan Teknologi
Fakulti Teknologi dan Kejuruteraan Elektronik dan Komputer
Universiti Teknikal Malaysia Melaka (UTeM)
|norfadzlia@utem|019-2421209|
Content

 Data Modeling and Data Models


 Data Model Basic Building Blocks
 Business Rules
 The Evolution of Data Models
 The Entity Relationship (ER) Model
 ER Model Components
 ER Model Notation
Data Modeling and Data Models

 Database design focuses on how the database structure will be used to store and
manage end-user data.
 Data modeling is the first step in designing a database and refers to the process of
creating a specific data model for a determined problem domain.
 A data model is a relatively simple representation, usually graphical, of more complex
real-world data structures.
 Within the database environment, a data model represents data structures and their
characteristics, relations, constraints, transformations, and other constructs to support a
specific problem domain.
Data Model Basic Building Blocks

Entity • Anything (a person, a place, a thing, or an event) about which data are to be
collected and stored.
• An entity represents a particular type of object in the real world.
• Entities are “distinguishable”—that is, each entity occurrence is unique and distinct.
• Example:
➢ STUDENT entities such as Aiman, Amsyar, Anis, Zikril, and Syahirah which are
distinguishable by a matric ID.

Attribute • Attributes are the equivalent of fields in file systems (think of Excel file).
• A characteristic of an entity.
• Example:
➢ A STUDENT entity would be described by attributes such as matric ID, last name,
first name, phone no, email, address, and study program.
Data Model Basic Building Blocks
Relationship • Describes an association among entities.
• Example Business Rule:
➢ A relationship exists between students and subjects that can be described as
follows:
o A student can register for many subjects, and each subject may be
registered by many students.

• Data models use three types of relationships:


➢ One-to-many (1:M or 1..*)
o Example Business Rule:
A painter paints many different paintings, but each one of them is painted
by only one painter.
o RELATIONSHIP: PAINTER paints PAINTING


Data Model Basic Building Blocks
Relationship ➢ Many-to-many (M:N or M:M or *..*)
o Example Business Rule:
A student can register for many courses, and each course can be registered by
many students.
o RELATIONSHIP: STUDENT registers COURSE

➢ One-to-one (1:1 or 1..1)


o Example Business Rule:
o Each Malaysian citizen owns an Identity card, and an identity card is owned
by only one Malaysian citizen.
o RELATIONSHIP: MALAYSIAN_CITIZEN owns IDENTITY_CARD

• Relationships are bidirectional.


• A PAINTER paints many PAINTINGs.
• Each of the PAINTINGs is painted by only one PAINTER.
Data Model Basic Building Blocks

Constraint • A restriction placed on the data.


• Constraints are important because they help to ensure data integrity.
• Data integrity encompasses the accuracy, reliability, and consistency of data over
time.
• Constraints are normally expressed in the form of rules.
o Example:
▪ An employee’s salary must have values that are between 6,000 and 350,000.
▪ A student’s GPA must be between 0.00 and 4.00.
Business Rules

 From a database point of view, the collection of data becomes


meaningful only when it reflects properly defined business rules.
 A business rule is a brief, precise, and unambiguous description of a policy,
procedure, or principle within a specific organization.
 Business rules, derived from a detailed description of an organization’s
operations, help to create and enforce actions within that organization’s
environment.
 Properly written business rules are used to define entities, attributes,
relationships, and constraints.
Business Rules

 Note that those business rules establish entities, relationships, and


constraints.
 Examples of business rules are as follows:
➢ Business Rule 1: A customer may generate many invoices.
➢ Business Rule 2: An invoice is generated by only one customer.
o Business Rules 1 and 2 establish two entities (CUSTOMER and INVOICE)
and a 1:M relationship between those two entities.
➢ Business Rule 3: A training session cannot be scheduled for fewer than
10 employees or more than 30 employees.
o Business Rules 3 establishes a constraint (no fewer than 10 people and
no more than 30 people), two entities (EMPLOYEE and TRAINING), and
a relationship between EMPLOYEE and TRAINING.
The Evolution of Data Models
The Relational Model

 The relational model was introduced in 1970 by E. F. Codd (of IBM) in


his landmark paper “A Relational Model of Data for Large Shared
Databanks” (Communications of the ACM, June 1970, pp. 377−387).
 Relation (sometimes called a table) as a matrix composed of
intersecting rows and columns. Each row in a relation is called a
tuple. Each column represents an attribute.
 The relational data model is implemented through a very
sophisticated relational database management system (RDBMS).
RDBMS is the ability to hide the complexities of the relational model
from the user.
 In the relational model, tables are related to each other through the
sharing of a common attribute (value in a column).
The Relational Model

Figure 1.8: Linking relational tables

 For example, the CUSTOMER table might contain a sales agent’s number that is also contained in the
AGENT table.
o A common link between the CUSTOMER and AGENT tables enables you to match the customer to
his or her sales agent, even though the customer data are stored in one table and the sales
representative data are stored in another table.
o For example, you can easily determine that customer Dunne’s agent is Alex Alby because for
customer Dunne, the CUSTOMER table’s AGENT_CODE is 501, which matches the AGENT table’s
AGENT_CODE for Alex Alby.
The Relational Model

Figure 1.9: Relational diagram

 A relational diagram is a representation of the relational database’s entities, the attributes


within those entities, and the relationships between those entities.
 In Figure 1.9, the relational diagram shows the connecting fields (in this case, AGENT_CODE)
and the relationship type, 1:M. Microsoft Access, the database software application used to
generate Figure 2.2, employs the ∞ (infinity) symbol to indicate the “many” side.
 In this example, the CUSTOMER represents the “many” side because an AGENT can have
many CUSTOMERs. The AGENT represents the “1” side because each CUSTOMER has only
one AGENT.
The Entity Relationship (ER) Model

 Peter Chen first introduced the ER data model in 1976.


 It was the graphical representation of entities and their relationships in a
database structure and complemented the relational data model
concepts.
 The relational data model and ER Model (ERM) combined to provide the
foundation for a tightly structured database design.
 ER models are normally represented in an entity relationship diagram (ERD),
which uses graphical representations to model database components.
ER Model Components

 Entity
 An entity is represented in the ERD by a rectangle, also known as an entity box.
 The name of the entity, a noun, is written in the center of the rectangle.
 The entity name is generally written in capital letters and is written in the singular form:
PAINTER rather than PAINTERS, and EMPLOYEE rather than EMPLOYEES.
 Usually, when applying the ERD to the relational model, an entity is mapped to a
relational table.
 Each row in the relational table is known as an entity instance or entity occurrence in the ER
model.
 Each entity is described by a set of attributes that describe the characteristics of the
entity.
 For example, the entity STUDENT will have attributes such as a matric no, a last name, and a first
name.

ENTITY_NAME
ER Model Components

 Relationships
 Relationships describe associations among data.
 Most relationships describe associations between two entities.
 When the basic data model components were introduced, three types of relationships
among data were illustrated: one-to-many (1:M), many-to-many (M:N), and one-to-
one (1:1).
 The ER model uses the term connectivity to label the relationship types.
 The name of the relationship is usually an active or passive verb.
For example, a PAINTER paints many PAINTINGs; an EMPLOYEE learns many SKILLs; an
EMPLOYEE manages a STORE.

1 M
ENTITY_1_NAME relationship ENTITY_2_NAME
ER Notations

Figure 1.10: The Chen and Crow’s Foot notations


CLASS ACTIVITY

 Draw the ER Model using Chen and Crow’s Foot Notation


1) Each student registers to many subjects.
2) Each subject is registered by many students.
3) Each student is assigned to an academic advisor.
4) An academic advisor is assigned to many students.

Step 1: Identify and draw entity(s) (noun).


Step 2: Identify the relationship type(s) and draw between entities.
Step 3: Identify the relationship name (verb) and write on the relationship
symbol.
CROW’S FOOT ERD
 Draw
Step 1: Identify
the ER Model
and draw
using
entity(s)
Chen and(noun).
Crow’s Foot Notation
1) Each student registers to many subjects.
2) Each subject is registered by many students.
3) Each student is assigned to an academic advisor.
4) An academic advisor is assigned to many students.

STUDENT SUBJECT ACADEMIC_ADVISOR


CROW’S FOOT ERD
 Draw
Step 2: Identify
the ER Model
the relationship
using Chentype(s)
and Crow’s
and draw
Foot
between
Notation
entities.
1) Each student registers to many subjects.
2) Each subject is registered by many students.
3) Each student is assigned to an academic advisor.
4) An academic advisor is assigned to many students.

STUDENT SUBJECT

ACADEMIC_ADVISOR
CROW’S FOOT ERD
Step 3: Identify the relationship name (verb) and write on the relationship
symbol.
1) Each student registers to many subjects.
2) Each subject is registered by many students.
3) Each student is assigned to an academic advisor.
4) An academic advisor is assigned to many students.

STUDENT registers SUBJECT

assigns

ACADEMIC_ADVISOR
CHEN ERD
Step 3: Identify the relationship name (verb) and write on the relationship
symbol.
1) Each student registers to many subjects.
2) Each subject is registered by many students.
3) Each student is assigned to an academic advisor.
4) An academic advisor is assigned to many students.

M N
STUDENT register SUBJECT

assign

1
ACADEMIC_ADVISOR
STUDENT register SUBJECT

assign

ACADEMIC_ADVISOR

Crow’s Foot ERD


Chen ERD
M N
STUDENT SUBJECT
register

assign

1
ACADEMIC_ADVISOR

You might also like