0% found this document useful (0 votes)
39 views

Lesson II. Entity-Relationship Model

This document discusses concepts related to entity-relationship modeling including: 1. Entity sets which are collections of entities that share attributes. Attributes can be simple, composite, multivalued, derived or null. 2. Relationship sets which define associations between two or more entity sets. Relationships have a degree based on the number of participating entity sets. 3. Design decisions around whether to model something as an attribute or entity set must consider factors like the number of attributes and whether attributes are similar types.

Uploaded by

Victor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Lesson II. Entity-Relationship Model

This document discusses concepts related to entity-relationship modeling including: 1. Entity sets which are collections of entities that share attributes. Attributes can be simple, composite, multivalued, derived or null. 2. Relationship sets which define associations between two or more entity sets. Relationships have a degree based on the number of participating entity sets. 3. Design decisions around whether to model something as an attribute or entity set must consider factors like the number of attributes and whether attributes are similar types.

Uploaded by

Victor
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

1

Contents
1. Concepts
2. Design decisions
3. Constrains
4. Keys
5. Entity-Relationship diagram
6. Weak entity sets
….. (and ER exercises)….
2

What is this about?


3

Possible questions about Concepts


1. What is a Entity set?
2. What is the domain of an attribute?
3. What is a simple attribute?
4. What is a composite attribute?
5. What is a multivalued attribute?
6. What is a derived attribute?
7. What is a NULL attribute?
8. What is a Relationship set?
9. What is the role of an entity in a relationship set?
4

1. Concepts
1.1. Entity Sets
a) Entity Is a thing or an object, in the real world, distinguishable from all other You
are an
objects.
Is? It exists by itself. May be concrete or abstract. entity
Examples: client, book, course.
It has properties You have
Properties A set of features that allow to univocally identify one entity
features
E.g.: person (name, surname, ID, …), bank loan, book, car?

b) Entity sets (e.s.)


A set of entities of the same type that All of You
Are? share the same properties or attributes. are an
Attributes have different values Entity Set
E.g.: clients, bank loan

Extension (of the entity set)


Extension
The individual entities that constitute a set are said to be the
extension of the entity set
E.g.: client Pepe is an extension of the entity CLIENTS
Disjoint? You are NOT
Disjoint? Not necessarily Disjoint
E.g.: employee, client, It is possible to be just
employee, just client or both of them.
5

Example 2 4
3
1

7
6

10
6

A entity is …

… entity set

Attributes
(entity or entity sets)
Are Are 1,85 cm
Associated values to each entity Handsome
Have a domain, or value set: the set of all possible
values. 75 Kg
Each entity may have its own value for each attribute Smart
Used for It allows us to Charming
- Represent an entity using a set of attributes
- Describe each entity using its set of attribute-value pairs

Types:
Elena
Composite 1) Simple and Composite. María
• Simple: Not divided into subparts Isabel
E.g.: (SecondName, Díaz) Dominica
• Composite: Make up by several values. Can be divided into de Silos
subparts de
E.g.: (FullName: Ana Aller Pérez), (Address: C/ Ancha 22 1ª Borbón y
Grecia
Multivalued Esc. 3º A)
2) Single-valued and Multivalued
• Single-valued: It has a single value for a particular entity
E.g.: loan number, ID, age
• Multivalued: an attribute has a set of values for a specific entity
E.g.: phone-number, dependent-name (0, 1 or more)
7

… something …

… entity sets

Composite attributes
8

Example
5
2 3
1
4

6
7
8

10
9

… distinguishable

… entity sets … Attributes. -> … Types

… Types:
3) NULL Phone #
It is not a value, it is a state. Means UNKNOWN
A field contains a NULL value when:
• it is missing (the value does exist, but we do not have that
NULL information)
Zero, blank? • it is not known
It is NOT: zero, blank or an “empty string”. Does not behave
like any of those values
Special treatment in queries, aggregates, etc.

Derived 4) Derived
Examples? Its value can be derived from the values of other related attributes Triennium
or entities
Sometimes they are physically stored into the database.
Some DBMS use a trick employing computed columns.

E.g.: employee: [hire date, seniority], [date-of-birth, age]


10

Relationship = ,,,

1.2. Relationship Sets


a) Relationship
Association among several entities (two or more)
E.g.: CustLoan: Customers, loans

b) Relationship sets (r.s.)


A set of relationships of the same type
E.g.: carbuyer: buyer, car;
bookbuyer: customer, book.

Participation
Association between entity sets
The entity sets E1, E2, …, En participate in relationship sets R
E.g.: buyers and cars participate in “carbuyer”
Relationship instance
Represents an specific relationship between two specific entities

Entity role
The function that an entity plays in a relationship
ü Generally, entity sets are distinct so roles are IMPLICIT and not specified.
ü The same entity set participates in a relationship set more than once
Labels
E.g.: recursive relationship set. Employee– work-for (worker & manager)
11

… association among entities

… Relationship sets
c) Features

Descriptive attributes
Attributes E.g.: depositor (customer, account) -> access-date
E.g.: enrolled-in (student, course) -> grade, grade-Term

Degree of relationship sets


Degree? The number of entity sets that participate in a relationship set
Binary: degree 2
E.g..: buyhouses (buyers , houses)
Ternary: degree 3
E.g..: Branch-loan-customer
N-ary: degree N
12

2. Design decisions
2.1. Attributes or Entity sets?
Situations- What is phone?-
a) Small number of attributes
Given an Employees Set (entity) that is going to store personal information (ID, fullname,
address and phone number).
b) Several attributes of the same type. Similar situation but including, for each phone, the
color, monthly cost, and location

Solutions
a) As attribute
Just one phone number -> Simple attribute
Every employees “n” phone numbers -> “N” attributes (not elegant).
Indefinite number of phones-> Multivalued attributed.
A number of attributes related to the phone (#, location, cost) -> Composite attribute

b) As Entity sets
A lot of information related to the phone is stored
Several employees sharing the same phone (and typically the phone has some
attributes)

Decision = f (specific problems, semantic related to the attribute)


13

Relationship or entity?

2.2. Relationship sets or Entity sets


Situations
a) Loan, as Relationship sets
a.1) A plain relationship
Without attributes. Between Customer and Branch
a.2) A small number of attributes
In addition, the relationship sets have small number of attributes (date, amount)
Usually, relationship sets one to many
What happens if several customers share the same loan?
Some loan attributes will be stored twice or more times
=> Redundancy or inconsistency

b) Loan, as entity sets


b.1) Several customers sharing a loan AND a customer could have several loans
b.2) There is a lot of information related to the loan (lots of attributes)
Usually, they are many to many relationships

Rule?
Relationship sets.: small number of attributes, low cardinality
Entity sets: lots of attributes, high cardinality (Many to many)
14

… relationship or entity?

… Relationship sets or Entity sets


Examples

1 2

3 4
15

Binary or N-ary?

2.3. Binary vs. N-ary relationship sets


Appears to be non-binary
Some relationships may be better S
represented using binary relationships

Replace ternary by two binary


Ternary relationship parents, relating a child to his/her
father and mother, is best replaced by two binary
relationships, father and mother.
Using two binary relationships allows partial
information. It is more flexible. ( e.g. only mother
being know)

No replaceable
There are some relationships that are NATURALLY
NON-BINARY
E.g. works-on
Entity sets employee, branch, and job
job entitles (manager, teller, auditor,
..)
–with attributes title and level
Ternary relationship:
Jose–Ordoño II branch- manager
Jose – Lancia branch - auditor
16

… binary or N-ary?

... Binary vs. N-ary relationship sets

Rule
Sometimes it is possible to replace n-ary relationships by sets of binaries

In general
Any non-binary relationship can be represented using binary relationships
by creating an artificial entity set

But
Also need to translate constraints
And translating all constraints may not be possible
17

3. Constraints
3.1. Mapping Cardinalities
a) Express
The number of entities to which another entity can be associated via a relationship set

b) For a binary relationship set R between entity sets A and B

One-to-one 1:1
One-to-one An entity in A is associated with at most one entity in B, and an entity in B is
associated with at most one entity in A.
One-to-many 1:N
One-to-many An entity in A is associated with any number (zero or more) of entities in B. An
entity in B, however, can be associated with at most one entity in A.
Many-to-one N:1
Many-to-one An entity in A is associated with at most one entity in B. An entity in B, however,
can be associated with any number (zero or more) of entities in A.
Many-to-many N:M
An entity in A is associated with any number (zero or more) of entities in B, and
Many-to-many
an entity in B is associated with any number (zero or more) of entities in A.
18

Mapping Cardinalities

… mapping cardinalities … for binary relationship


sets

One to one One to many

Note: Some elements in A and B may not be mapped to any elements in the other set
19

… mapping Cardinalities

… mapping cardinalities … for binary relationship


sets

Many to one Many to many


Note: Some elements in A and B may not be mapped to any elements in the other set
20

Constraints

… 3. Constraints

c) Participation

Of an Entity Set in a Relationship Set.:

Total (double line?) only in basic ER Diagram


Every entity in the entity set
participates in at least one
relationship in the relationship set

Partial
Some entities may not participate in
any relationship in the relationship In the Extended ER diagram, we
set will specify the participation with
the mapping cardinality:

Total:
(1,1) or (1, n)
Partial:
(0,1) or (0, n)
21

4. Keys (Identifiers)
4.1. Entity Sets
a) Superkey
Is a set of one or more attributes that, taken collectively, allow us to identify uniquely an entity in
the entity set
Some attributes can not be required for identifying an entity
Must be unique but not necessarily irreducible
E.g..: ID, SSN (SocialSecurityNumber); DNI+CustomerName, SSN+PhoneNumber

b) Candidate keys
Are Superkeys for which no proper subset is a superkey (a minimal superkey)
Properties:
1. Unique: there is not two entities with the same candidate key values
2. Irreducible: the set is minimal because there is not proper (or strict) subset of these
attributes for which (1) holds
E.g..: DNI; name+DataBirth+address; CustomerID, SSN, PhoneNumber

c) Primary key
The candidate key chosen
as the principal means of identifying entities within an entity set.
Primary identifier = primary key
Alternative identifier = each of the other candidate keys
22

Keys

4.2. Relationship sets


How is it possible to distinguish among the
various relationships of a relationship set?

Let R be a relationship set involving entity sets E1, E2, …, En


Let primary-key (Ei) denote the set of attributes that form the primary key for entity set Ei.
Assuming:
- attribute names of all primary keys are unique
- Each entity set participates only once in the relationship

a) If the relationship R has not attributes associated with it,


primary-key(E1) U primary-key (E2) U … U primary-key (En) (1)
b) If the relationship R has attributes a1, a2, …, am associated with it,
primary-key(E1) U primary-key (E2) U … U primary-key (En) U {a1, a2, …, am} (2)

In both of the above cases, (1) forms a superkey for the relationship set
The primary key will be chosen depending on the cardinality of the relationship set

In an E-R Diagram, the relationships have not “filled circles” for denoting a Primary Key
23

5. Entity-Relationship Diagram
5.1. It Express
The overall logical structure of a database graphically.

5.2. Components b) Ellipses …


only in basic ER Diagram

a) Rectangles
represent Entity sets
Strong: §Attribute (descriptive) –empty circle-:
§ Primary identifier (primary key) -full:
Weak: § Candidate identifier:
§ Composite identifier:

c) Diamonds § Multivalued:
§ Composite attribute:
Represent relationship sets
§ Multivalued composite attribute:
Regular: § Optional attribute (dashed line):
§ Derivative Attribute: It has a label usually related to
ID EX
the derivative function used for compute it
Weak:
only in basic ER Diagram
24

E/R Diagram

... Components
d) Lines
- Associating attributes (undirected line)
- to an entity set
- to a relationship set
- Associating RS with ES
- undirected line: Cardinality 1
- directed line: Cardinality N

e) Other

e.1) Cardinality
(min, max) -> Entity sets
1:N -> Relationship sets
e.2) Attributes of relationship sets
Joined with a connecting line to the diamond
e.3) Labels for indicating roles
In recursive (or ring) relationships
e.4) Non binary relationships
Diamond with three (or more) lines connecting
with entity sets
25

E/R Diagram

5.3. Other notations


1) Basic Chen

We do not use basic Chen!


Notation

Example
26

E/R Diagram

5.3. Other notations


… 1) (Chen Extended, more or less)

Notation

Example

Almost ours!
27

E/R Diagram

5.3. Other notations


… 1) (Chen Extended, more or less)

Similar, but not yet ours!


28

E/R Diagram

… 5.3. Other notations


2) Martin’s

Notation

More details and alternative notation


29

E/R Diagram

… 5.3. Other notations


3) Crow’s foot
We do not use it!

Notation

Example
30

E/R Diagram

… 5.3. Other notations


4) Barker’s
We do not use it!

Notation
31

E/R Diagram

… 5.3. Other notations


5) UML
We do not use it!

Notation
32

E/R Diagram

… 5.3. Other notations


6) Other We do not use it!

Information
IDEF1X
Engineering
33

E/R Diagram

… 5.3. Other notations


5) UML
We do not use it!

Example
34

Weak does not survive !!

6. Weak entity sets


6.1. Definition
An entity set that have not sufficient attributes to form a primary key
The entity set that do have them is termed a strong entity set

The existence of entity “x” depends on entity “y” exists

y: identifing (or owner) entity set (own the x set)


x: weak entity (is existence dependent on y)
If y is deleted, x must be deleted

Example only for illustrating the WEAK entity set. Relationship set representation is not right

See EER: Existence dependency and Identification dependency


35

…weak does not survive !!

…. 6. Weak entity sets

6.2. Features
Other typical features of weak entity sets are:

- Relationship Cardinality
Will be 1:N
Do not have attributes
- Discriminator:
The set of attributes that allow us to distinguish among all those entities in the
weak entity set that depend on one particular strong entity
- Primary key:
Discriminator + primary key of identifying entity set

Example only for illustrating the WEAK entity set. Relationship set representation is not right
36

Example 3

1 4
6

8 7
2

10
37

Example

NRS: Semantic that is not reflected

You might also like