Chapter II
Chapter II
Chapter II
Conceptual Model
Entity Association(/Relationship) Model
Practical Process
Steps in the data modeling process
• Plan project.
• Determine requirements.
• Specify entities.
• Specify relationships.
• Determine identifiers.
• Specify attributes.
• Specify domains.
• Validate model.
2
How to build a database
3
Conceptual Modeling
Conceptual Model (Entity Association/Relationship model)
• Also known as Entity-Association Diagrams (EAD)
• Introduced in 1976 by Peter Chen
• Graphical representation
• Top-Down-Approach for modeling
4
The Entity / Association Model - Basic Concepts
• The E / A model is a graphical formalism for data modeling
• Success due to:
• graphic language
• Represent the entity by a rectangle
• represent the association by a lozenge or circle
• simple concepts:
• Things (objects) -> entities
• links between things (objects) -> association/relation
• grouping things of the same nature:
• feature classes, association classes.
5
Purpose of Entities
• Knowing how to organize and classify data makes it possible to draw useful
conclusions about seemingly random facts
• Our technology-rich world produces vast quantities of facts in need of structure and
order
• It is important to learn about entities because they are the things about which we
store data
• For example;
• A school needs to store data about (as a minimum):
STUDENTs, TEACHERs, COURSEs, ROOMs, GRADEs
6
Specifying your entities
• An entity is something that the users want to track; something the users want to keep
data about
• Entities
• Can be physical things or logical concepts: an object, an event, a place, a person,
..., a thing,
• Are identifiable; you can tell one from another.
Entiy Name
• Usually a noun
• Entity class formalism: graphical representation
7
Entities
MOVIE Actors
CINEMA
Realizers
8
Entities and Instances
• An instance is a single occurrence of an entity
9
Instances vs Entity
• Is DOG an instance or an entity?
• It depends:
• If we consider many different kinds of animals, it makes sense to think of the entity ANIMAL
to include instances DOG,CAT, HORSE and so on
• But what if we run a dog-breeding business? We will need to keep data on may different
breeds of dog, but not on other species of animal
• For a dog-breeder, it is more natural to think of an entity DOG to include instances TERRIER,
POODLE,LBRADOR and so on
10
Specifying Association/Relationships
• Includes:
• Relationship type.
• Name of the relationships.
11
Properties = Attributes
• Elementary data that we perceive on an entity or an association
• Example:
• Surname, first name for the entity ACTORS
• Title and Director for FILMS
• Name and Address For CINEMA
• Help you distinguish between once instance and another by providing greater
detail for the entity
12
What is an Attribute
13
Attributes
• Attributes have values. An attribute value can be a number, a character string, a date,
an image, a sound,etc.
• These are called “data types” or “formats”
• Every attribute stores one piece of data of one specific data type.
14
Attributes
• What is the data type of each attribute in CUSTOMER
• For example:
• Family name is a character string, attributes are single-valued
• Each attribute can have only one value (at any point in time) for each instance of the entity
15
Attributes
• Some attributes (such as age) have values that constantly change
• These are called volatile attributes
• Other attributes (such as order date) will rarely change, if eve
• These are nonvolatile attributes
• If given a choice, select the nonvolatile attribute
• For example, use birth date instead of age
16
Attributes
• Some attributes must contain a value, these are mandatory attributes
• For example: in most businesses that track personal information, name is required
• Other attributes may either contain a value or be left null- these are optional attributes
• For example: cell phone number is often optional except in mobile or wireless applications
17
Type of Attributes
• Atomic Attributes
• Basic, single-valued attributes
• Composite Attributes
• Attributes as structured data types
• Can be represented as a hierarchy
• Derived Attributes :Attributes derived from other data
• Noted with dashed circle
• Examples: Number of employees in dep, employee age, employee
yearly salary
• Multi-valued Attributes :
• Attributes with list of homogeneous entries
• Noted with double circle
Database Design 18
Attributes: Example
• Email address could be a mandatory attribute for EMPLOYEE in an email
application, but an optional attribute for CUSTOMER in an online
catalog
• Give one or two examples of the values that each EMPLOYEE attribute
might contain
19
Example
Database Design 20
Properties
• For associations:
• BE CAREFUL, the properties/attribute that we put in an
association/relation must obligatorily connect the entities
• For example, the Grade connects the student and the professor
23
Identifiers
• Think about all the students in the classroom
• Which attributes allow you to pick a single student from the rest of the class?
24
Determining Identifier
• Identifier is an attribute or group of attributes that uniquely identifies an entity
instance.
• One identifier (Uniqueness)
• We prefer the shortest, most natural identifier (no order form, no student, ...)
• The identifier is not variable in time
25
Identifier
Objective:
• Each occurrence must be uniquely and unambiguously identifiable, to
be distinguished from all others
Identifier:
• Property (attribute) or group of properties whose value
unambiguously identifies an entity or a link of a class (identifier =
primary key).
26
Weak entities
• A weak entity is one that needs another entity to be defined.
• Weak entities are entities whose primary key is :
• a subset of a primary key of another entity :
• composed of the primary key of another entity and another attribute (which
belongs to the weak entity)
• noted with a double rectangle.
28
Example
• Weak entities are represented with double rectangular box in the ER Diagram and the
identifying relationships are represented with double diamond. Partial Key attributes
are represented with dotted lines.
30
Example
• A Company is organized into departments.
• Each department has a number and an employee who manages the department.
• We keep track of the start date when that employee started managing the department.
• A department may have several locations.
• A department controls a number of projects.
• Each of which has a name, a number and a single location.
• We store each employee’s name, Id number, address, salary, and birth date.
• An employee is assigned to one department, but may work on several projects, which are not
necessarily controlled, by the same department.
• We keep track of the number of hours per week that an employee works on each project.
• We also keep track of the direct supervisor of each employee.
• We keep track of the dependents of each employee.
• We keep each dependent's name, birth date and relationship to the employee.
• The conceptual schema is used as a reference to ensure that all user’s data
requirements are met, and the requirements do not include any conflicts.
32
Conceptual Design
33
Detailed Conceptual Design
34
Detailed Conceptual Design
35
Entities and Attributes
• What are the attributes of a monitoring site?
Attributes Values
• Site Name: Little Bear River near Wellsville
• Site Code: USU-LBR-Wellsville
• Latitude: 41.643457
• Longitude: -111.917649
• Elevation: 1365 m
• State: Utah
• County: Cache
• Description: Attached to SR101 bridge.
• Site Type: Stream
Entity Name
Entity
Multiplicity : cardinalities of associations/relationships
38
Relationships
39
One to Many
40
One to Many
41
One to Many
42
One To One Relationship
43
Many to Many
44
Many to Many
45
One to One
46
Cardinality And Multiplicity
Each association depicts the complexity or degree of each relationship, and this is called
cardinality.
• Cardinality defines the number of occurrences of one entity for a single occurrence
of the related entity.
• Because all relationships are bi-directional, cardinality must be defined in both
directions for every relationship.
• A multiplicity is made up of a lower and an upper cardinality.
• A cardinality is how many elements are in a set while a multiplicity tells you the
minimum and maximum allowed members of the set.
47
Multiplicity: Cardinality of a relationship
• Two numbers (min, max) representing the minimum number of times and the
maximum number of times an entity participates in an association.
48
Multiplicity: Cardinality of a relationship
49
Relationship Notation
• Multiple notation systems are used
• Each software program is a little different
• Most common is “Crows Foot” and Chen Notation
Crows Foot Chen Notation
0 .. m
1 .. m
1 .. 1
0 .. 1
Relationship Cardinality and Participation
A1 R1
T1
A2 R2
T2
A3 R3
A4 R4
T3
A5 R5
A6 R6
Reading Cardinality and Participation
Relationship Examples
58
Relationship Notation
• Multiple notation systems are used
• Each software program is a little different
• Oracle use a variation of “Crows Foot” developed by Richard Barker
Crows Foot Chen Notation
0 .. m
1 .. m
1 .. 1
0 .. 1
Types of Binary Relationship
Crow's foot
Database Design 60
Modeling cardinality and relationship
Database Design 61
In our written exercises we will use Chen Notation
Database Design 62
0 to 1
63
1 to 1
64
0 to many
65
1 to many
66
Example
67
How to start? What to do?
• Find the basic entity types
• Find the attributes of entities
• Decide to which entity an attribute should be assigned
• Which attributes are key attributes?
• Some attributes are better modeled as own entities, which ones?
• Define the relationship types
• Which role do entities play?
• Do relationships require additional entity types?
• Are the relationships total? Identifying? Are weak entities involved?
• What are the cardinalities of the relationship type?
68
Validating Model
• A data model is wrong if it does not accurately reflect the ways the
users think about their world.
• Data models are validated through a series of reviews
• Normally, a team review is followed by user reviews.
• E-A model as well as prototypes of forms and reports may be used
to communicate to users features of the data model.
69
Association n-dimension(n=2):Binary Relationship
70
Association n-dimension (n=3):Ternary Relationship(n-ary)
Multiplicity
• 1 Project and 1 Supplier supply P parts
• 1 Project and 1 Part supplied by N suppliers
• 1 Supplier and 1 Part supply for M projects
Example: A Typical Relationship Set
72
Example: Ternary Relationship
name addr name manf
Preferences
Drinkers
name addr
73
Recursive Relationships
• Recursive relationships are relations between entities of the same type
• Use roles to differentiate cardinalities
Database Design 74
Association n-dimensions(n=1): Unary Relationship/Association
75
Details on the occurrences of association
• Definition:
An association occurrence is an occurrence of each of the entities involved
76
Example
price name category
Start Year
name
makes Company
Product
Stock price
This model is correct only if you manage a single score per student at a
Course (for example, the average)
Or →
78
Details on the occurrences of association
0,n
date
Date
Example: on a given date, for a course., several students may have same grade
79
Relationship set as an entity set: Aggregation
name
ssn lot
Id GPA
Students Courses
• Cardinalities?
Enrolled_In
Grade
Example 2
83
Example 2 Answer
Age
Patients Drug
Prescribed
Dosage #days
84
Example
85
Solution
Release
Date Model
Plate
no
Numbe
Has
Person Car
has 1-1
1-N
86
Practice EA Diagram
Suppose you are given the following requirements for a simple database for the National Hockey
League (NHL):
· the NHL has many teams,
· each team has a name, a city, a coach, a captain, and a set of players,
· each player belongs to only one team,
· each player has a name, a position (such as left wing or goalie), a skill level, and a set of injury
records,
· a team captain is also a player,
· a game is played between two teams (referred to as host_team and guest_team) and has a date
(such as May 11th, 1999) and a score (such as 4 to 2).
Draw a clean and concise EA diagram for the NHL database
List your assumptions and clearly indicate the cardinality mappings
as well as any role indicators in your EA diagram.
87
using the Chen notation
88
Constraints
89
Integrity constraints
• Integrity constraints ensure that the data insertion, updating, and other processes
have to be performed in such a way that data integrity is not affected.
90
Specifying Constraints in Data Models
• EA model
• domain and key constraints over entities
• participation and cardinality constraints over relationships
• Relational Model
• domain constraints, entity identity, key constraint, functional dependencies --
generalization of key constraints, referential integrity, inclusion dependencies --
generalization of referential integrity.
91
Domain Constraint
• In the schema, every attribute is declared to have a type --- integer, float, date,
Boolean, string, etc.
• DBMS can check if insertion violates domain constraint and reject the insertion.
92
Key Constraint
• Each relation has a primary key.
• Superkey:
• Set of attributes such that if two tuples agree on those attributes, then they agree on all
the attributes of the relation
• Note: the set of all the attributes of a relation is always a superkey.
• Candidate key:
• Superkey is reduced to the minimum number of columns required to uniquely
identify each row.
• Primary key:
• one of the candidate keys
93
Disallowing Null Values
• Example:
• in sales(customer, salesman, date, amount, saleID) we may not want ‘customer’ to
contain a null value.
94
Entity Integrity Constraint
• For Example, if more than one tuple has a null value in its primary key, we may not be
able to distinguish them .
95
Foreign Key and Referential Integrity Constraint
• Consider following 2 relation schemas:
• R1(A1, A2, …An) and R2(B1, B2, … Bm)
• LegalGrades
Grade
A we will have a referential integrity
B constraint stating that
C every value of student-grades.grade
D must also be a value of
F LegalGrades.grade
97
The concept of integrity constraint
• Static:
• They must be constantly checked:
• Start_date <End_date
• an employee's salary must be less than her manager’s
• Dynamics:
• Validated with each update of the data:
• Loan of a book to a reader, provided that the total number of borrowed books is less than or equal to 3
• References:
• Linked to associations, check the existence of an occurrence of the entity concerned
• You can not create an order for a supplier who does not exist
98
Inclusion Dependencies
• Generalization of referential integrity constraint.
99
Example
Here, by the constraint of inclusion, it is specified that all couples (software,
department) extracted from all the triplets (software, department, server) of the
association Installation are obligatorily included in all couples (software, department
) of the association buy.
Software Server
Department
buy
Constraints [exclusion]
Rent
Software Department
buy
101
Data Modification and Integrity Constraints
• Modification, insertion and deletion requests can lead to violations of integrity
constraints.
• Key constraint, entity identity, null value constraint, referential integrity, inclusion dependencies,
functional dependencies, multivalued dependencies.
• must check for violation at end of each operation and suitably allow or disallow
operation.
102
Example
• Relations
• CourseOfferings(C#, semester, instructor)
• Takes(S#, C#, semester, grade)
• What should happen to tuples in Takes that refer to CS101 and semester 2-91??
Example
Description Product
Street address
Description Product
Employees Departments
Manages
Cardinalities?
Dependent
Works_In
Child
name age
Exercise 2.2
• Although you always wanted to be an artist, you ended up being an expert on databases because you love to
cook data and you somehow confused database with data baste. Your old love is still there, however, so you
set up a database company, ArtBase, that builds a product for art galleries. The core of this product is a
database with a schema that captures all the information that galleries need to maintain.
• Galleries keep information about artists, their names (which are unique), birthplaces, age, and style of art.
For each piece of artwork, the artist, the year it was made, its unique title, its type of art (e.g., painting,
lithograph, sculpture, photograph), and its price must be stored. Pieces of artwork are also classified into
groups of various kinds, for example, portraits, still lifes, works by Picasso, or works of the 19th century; a
given piece may belong to more than one group.
• Each group is identified by a name (like those just given) that describes the group. Finally, galleries keep
information about customers. For each customer, galleries keep that person’s unique name, address, total
amount of dollars spent in the gallery (very important!), and the artists and groups of art that the customer
tends to like.
• Draw the ER diagram for the database.
Exercise 2.2
year type
name title
price
Multiplicity?
Customer Like_Artist Artist Paints
address style
cust_id name
112
Exercise 2.4
113
Exercise 2.6 : Cardinalities in case of single match
Play
Player Win MatchTennis
Relational Model
09/03/2022 120
Practice: Oracle Data Modeler