18
db design / ER Modeling 2003 1 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 [email protected]

Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 [email protected]

Embed Size (px)

Citation preview

Page 1: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 1

319B Database SystemsER-Modeling Part 2

Wilhelm Steinbuss

Room G2.04, ext 4052

[email protected]

Page 2: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 2

3. Relationship(types)

• Relationship- and Rolenames

• Cardinalities

• Mandatory / optional

• Reflexive relationship types

• N-ary realtionship types

• Gerund

• XOR relationship types

Page 3: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 3

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)

Page 4: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 4

Example

Instead of

We can use

Page 5: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 5

3.1 Relationship- and Rolenames

A relationship can be named and the involved entities could have an assigned role

Example:

Page 6: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 6

3.2 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

person address

Page 7: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 7

3.3 Reflexive relationship type

Relation between entities of the same type

Example:

Page 8: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 8

Reflexive relationship (Cont.)

A person can be married more than once over time:

Page 9: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 9

3.3 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

Page 10: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 10

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.

Page 11: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 11

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

Page 12: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 12

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

Page 13: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 13

3.5 n-ary Relationship types

A relationship which has more than two entities involved

Example:

Page 14: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 14

3.6 Gerund

A gerund is an associative entity which is treated like a fundamental entity

Example:

Page 15: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 15

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

Page 16: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 16

Solution consultancy

Page 17: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 17

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)

Page 18: Db design / ER Modeling 20031 319B Database Systems ER-Modeling Part 2 Wilhelm Steinbuss Room G2.04, ext 4052 steinbus@cs.waikato.ac.nz

db design / ER Modeling 2003 18

3.7 XOR Relationship types

Exactly one of the relationships which are marked with the XOR construct is valid

Example:

(ex. 5)