Conceptes varis sobre el model entitat relació: Conjunt d'entitats, entitats, atributs i tipus d'atributs, tipus de relacions,
cardinalitat, entitats dèbils i fortes
Entity sets, attribute, relationship, type of attribute, cardinality, relationship type, weak and strong entities. Null values, identifier
2. Miquel Boada Artigas
Database design
What do we need? / Specifications
Conceptual model
Entity-Relationship(ER)
Relational model
Data definition language
3. Miquel Boada Artigas
Model ER - Elements
●
Entity sets/entities
●
Relationship sets/Relationship
●
Attributes
4. Miquel Boada Artigas
Entity
●
Object (concrete or abstract) distinguishable from other objects.
●
Example
–40232423, Artur Mas (concrete: particular person)
●
Example
–Vacances a la Costa Brava, des del 03/08/2015 fins el 21/08/2015. (abstract)
5. Miquel Boada Artigas
Entity sets
●
Set of entities of the same type
●
Examples: Workers, vehicles, buildings ...
●
Examples: Departments, Salaries, holidays ...
7. Miquel Boada Artigas
Exercicis
●
Indica els conjunts d'entitats necessàries per a la gestió d'una botiga d'informàtica.
●
Indica els conjunts d'entitats necessàries per a la gestió del club de Handbol de
Granollers.
●
Indica els conjunts d'entitats necessàries per a la gestió d'un parking.
●
Indica els conjunts d'entitats necessàries per a la gestió d'un joc de rol (informàtic).
9. Miquel Boada Artigas
Attributes
●
Describes a property or characterstic of an entity.
●
An entity set is composed by one or more attributes.
●
It's identified by a name.
●
Two attributes with the same name are not allowed in the same entity
set.
12. Miquel Boada Artigas
NULL values
●
Special name for «unknown» value.
●
Space or zero is not NULL (space and zero is a known values).
●
Examples:
–Qualification: NULL. (No results yet).
–Final match result: NULL (Not started).
13. Miquel Boada Artigas
Derived attribute
●
His value can be obtained from other attributes or related entities.
●
Examples:
–Age → if an attribute «date of birth» exists.
–Matches won → can get this value from an entity set «results».
14. Miquel Boada Artigas
Composite attribute
●
An attribute is composite if we can divide it on some other attributes.
●
The model ER is clearer.
●
Example:
–Name (person): name , surname.
–Direction: city, address, number ...
–Temperature: value, units.
15. Miquel Boada Artigas
Attribute hierarchy
●
A composite attribute can be formed by other
composite attributes.
Direction
City
Postal code
Name
Address Number
Simple attributes
Composite attributes
16. Miquel Boada Artigas
Univalued / multivalued
●
Can store one value => univalued attribute.
●
Can store many values => multivalued attribute.
●
Examples univalued:
–Name, date of birth (person), model (vehicle) …
●
Examples multivalued:
–Telephone, colors (product), languages, ...
17. Miquel Boada Artigas
Fictitious attributes
●
They don't add any meaning to the entity.
●
They are used like fictious identifiers attributes
●
Their use is not recommended.
●
Their use is acceptable when an entity is identified for 4 or more attributes.
●
Their implementation is based on the use of autonumeric values (1, 2, 3, ….)
19. Miquel Boada Artigas
Relationship
●
Is a correlation between two or more entities.
●
Examples
–Pau Pi is learning databases systems.
–Volkswagen is producing a new car model.
–Pau Pi has bought a HP 14z Laptop computer.
20. Miquel Boada Artigas
Relationship sets
●
Is a correlation between two or more entity sets.
●
Examples
–Teachers and students.
–Customers and invoices.
–Warehouses and articles.
22. Miquel Boada Artigas
Relationship sets type (1:1)
●
One entity can be related to only one entity, and viceversa.
●
It is not frequent.
●
Example:
–Country and president
a1
a2
a3
a4
...
an
Entity set A
b1
b2
b3
b4
...
bn
Entity set B
23. Miquel Boada Artigas
Relationship sets type (1:N) / (N:1)
●
One entity can be related to many entities.
●
(1:N/N:1) depends on the order of entities sets.
●
Example:
–Country and monuments
a1
a2
a3
a4
...
an
Entity set A
b1
b2
b3
b4
...
bn
Entity set B
(1:N)
a1
a2
a3
a4
...
an
Entity set A
b1
b2
b3
b4
...
bn
Entity set B
(N:1)
24. Miquel Boada Artigas
Relationship sets type (N:M)
●
One entity can be related to many entities and
viceversa.
●
Example:
–Films and actors
a1
a2
a3
a4
...
an
Entity set A
b1
b2
b3
b4
...
bn
Entity set B
25. Miquel Boada Artigas
Participation
●
Total: all entities are related with another entity.
●
Partial: there're any entities not realet with any entity.
–«A» has a total participation in «B».
–«B» has a partial participation in «A».
a1
a2
a3
a4
...
an
Entity set A
b1
b2
b3
b4
...
bn
Entity set B
26. Miquel Boada Artigas
Participation - Examples
●
Total
–Vehicle and insurance.
–Book and author.
●
Partial
–Students and companies.
–Workers and computers.
27. Miquel Boada Artigas
Degree
●
Number of entity sets involved in a relationship.
●
Examples:
–Team has players: binary relationship.
–Players commit fouls in a match: ternary relationship.
28. Miquel Boada Artigas
Cardinality
●
Cardinality: set a minimun and maximun value to the relationship.
–Basket player commits fouls in a match.
–Relationship set: commit.
–Relationship set type: 1:N (player-fouls)
–Minimun value: 0
–Maximun value: 5
–
29. Miquel Boada Artigas
Candidate key
●
An entity can be identified by using differents attributes.
●
All the attributes that identifies an entity is a candidate key.
●
Example:
–A worker could be identified by: SSN, NIF. Both attributes are
candidate.
31. Miquel Boada Artigas
Weak Entities
●
The existence of a weak entity depends on the existence of an identifying entity type (strong entity).
●
A weak entity has a relationship set (1:N or N:1), where 1 is strong entity and N weak entity.
●
Examples:
–Course (strong) and course-offering (weak).
–Match (strong) and goals (weak).
–Customer (strong) and sales (weak).
32. Miquel Boada Artigas
Graphical representation
Entity set Rel. set
Weak
entity set
Identifying
rel. set
Entity set Rel. setEntity set Rel. set
Entity set Rel. set
37. Miquel Boada Artigas
Exemple 1
Es necessita dissenyar un model ER que permeti controlar quins mòduls i
unitats formatives fa cada alumne.
Cada mòdul s'identifica per un codi. Altra informació que conforma el mòdul és
el nom associat i el total d'hores de les unitats formatives que el conformen.
De cada unitat formativa s'emmagatzemarà el seu codi, el nom de la unitat
formativa i les hores que la componen.
38. Miquel Boada Artigas
Biblioteca
Es necessita un model ER per a controlar la gestió d'una
biblioteca. Els socis de la biblioteca poden agafar llibres per un
període determinat. Es vol saber quins llibres té cada soci.
El temps que es pot agafar cada un dels llibres deprendrà del
tipus de llibre.
40. Miquel Boada Artigas
Reflexive relationship
●
Two entities belonging to the same entity set can be related. When
this occurs , we have an reflexive relationship.
●
Examples:
–An employee is supervised by one manager
–A course requires previous courses.
43. Miquel Boada Artigas
Ternary relationship sets
●
A ternary relationship occurs when 3 entity sets are
involved in a relationship.
●
The relationship sets type is set taking two entities
sets and determining the type respect the other one.
44. Miquel Boada Artigas
Example
SOME ENTITY SETS VALUES
Supplier Part Vehicle
Michelin Wheel Volkswagen
Firestone Motor Renault
Electronic Motors Ford
Tesla Motors
Donada una peça (ex.: roda) i un proveïdor,
es pot suministrar a molts vehicles?
Resposta sí: Supplier/Part → tipus relació N
45. Miquel Boada Artigas
Example
SOME ENTITY SETS VALUES
Supplier Part Vehicle
Michelin Wheel Volkswagen
Firestone Motor Renault
Electronic Motors Ford
Tesla Motors
Donat un tipus de vehicle i una peça, aquesta
pot ser suministrada per molts proveïdors?
Resposta sí: Vehicle/Part → tipus relació M
N
46. Miquel Boada Artigas
Example
SOME ENTITY SETS VALUES
Supplier Part Vehicle
Michelin Wheel Volkswagen
Firestone Motor Renault
Electronic Motors Ford
Tesla Motors
Un proveïdor pot suministrar moltes peces per un tiNM
Resposta sí: Vehicle/Supplier → tipus relació P
NM
P
M:N:P
48. Miquel Boada Artigas
Generalization / Specialization
●
Two or more entity sets combines to form a higher level entity sets (generalization)
●
1 entity sets breaks in 2 or more entity sets to form a lower level entity sets
(specialization)
●
Examples:
–An entity sets teacher and student combines to form an entity sets Person (generalization)
–An entity sets vehicle breaks in different entity sets: car, truck, bus ... (specialization)
49. Miquel Boada Artigas
Generalization / Specialization
●
The attributes of the higher entity sets are inherited to the lower
level entity sets.
●
Each lower level entity sets has they own attribute sets.
–Example: dni is an attribute for person entity sets, while average
qualification is an attribute for student entity sets.
52. Miquel Boada Artigas
Projectes
Es necessita un model ER per a controlar els projectes d'una empresa. Cada projecte està associat a un tipus (nous
productes, informàtica,...). Cada tipus de projecte té associat a un responsable, que serà l'encarregat de vetllar pel
bon funcionament de tots els projectes associats al tipus en concret. Apart del cap de projectes, a cada projecte hi
estan assignades una sèrie de persones. Una persona pot treballar en varis projectes al mateix temps.
Apart des recursos humans, per a cada un dels projectes es necessiten una sèrie de materials. Cada material
s'identifica per un codi. Un material només es podrà utilitzar en un projecte. Altra informació que es vol
emmagatzemar del material és la quantitat i el preu unitari.
De cada projecte és important saber el total de persones que té associades i el cost del material del mateix.