db design / ER Modeling B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052
db design / ER Modeling Relationship(types) Relationship- and Rolenames Cardinalities Mandatory / optional Reflexive relationship types N-ary realtionship types Gerund XOR relationship types
db design / ER Modeling Relationship types A relationship type is an assoziation between several (not necessary different) entity types (and so it is an associative entity type because it describes a fact referencing more than one entititype) If these associative entity type does not own additional attributes the rectangle and the arrows are dropped (except for n-ary relations)
db design / ER Modeling Example Instead of We can use
db design / ER Modeling Relationship- and Rolenames A relationship can be named and the involved entities could have an assigned role Example:
db design / ER Modeling Cardinalities Cardinality ist the number of entities (instances of an entity type) with which one entity could be connected Example: a person can have several addresses; an address is assigned to exactly one person personaddress
db design / ER Modeling Reflexive relationship type Relation between entities of the same type Example:
db design / ER Modeling Reflexive relationship (Cont.) A person can be married more than once over time:
db design / ER Modeling Mandatory / optional Lay down whether a relation must be or is optional Example: - a person have not to own an account, but can own more than one - an account must be owned by at least one person, but can be owned by many persons
db design / ER Modeling Example Zoo There are a lot of animal species in the zoo. Every animal species can be placed within exactly one enclosure type (aquarium, cage, outdoor enclosure). For each enclosure type exists possibly more than one enclosure with different amount of space (or volume). In one enclosure there is at most one animal species Each animal needs a minimum of space allocated (e.g. 12 m², 0.1 m³). The number of actual allocated animals in an enclosure should be recorded Every animal species is attended by at exactly one conservator Add additional requirements if necessary.
db design / ER Modeling Solution Additional requirements: - In an enclosure type different animal species can be placed - An enclosure is of exactly one type - An animal species can be placed in more than one enclosure - perhaps an enclosure is empty - perhaps an animal species is not placed into an enclosure
db design / ER Modeling Exercise bicycle manufacturer The bicycle manufacturer produces more than one bicycle type A bicycle consists of more than one assembly An assembly contains several parts (or other assemblies) Parts can be supplied by several suppliers For an order a recording have to be done including the number of ordered parts
db design / ER Modeling n-ary Relationship types A relationship which has more than two entities involved Example:
db design / ER Modeling Gerund A gerund is an associative entity which is treated like a fundamental entity Example:
db design / ER Modeling Example consultancy A consultancy realizes projects with their customers A customer can have more than one project Each project is leaded by exactly one consultant For each month the number of hours which an employee has worked for a project are recorded These records are the base for the invoice An invoice must have at least a relation to one of the records
db design / ER Modeling Solution consultancy
db design / ER Modeling Exercise Library A book in a library is published by a publishing company For each book type exists at least one book instance A book must have assigned at least one or more author(s) There can be keywords for every book For each person who borrows books an address is necessary An user of the library can borrow books or make an advance booking There is a fee (sliding scaled) per day for every overdraft (e.g. $1 for each day in the first week, $2 for each day in the second etc.) An overdraft can cause (one or more) overdue notification(s) An overdue notification can be related to more than one overdraft For every overdue notification there is a fee (depending on the previous number of notifications; e.g $1.50 for the first, $2 for the second and so on)
db design / ER Modeling XOR Relationship types Exactly one of the relationships which are marked with the XOR construct is valid Example: (ex. 5)