informationslogistik unit 2: the entity-relationship...

40
The Entity-Relationship Model SQL Informationslogistik Unit 2: The Entity-Relationship Model Ronald Ortner und David Pietzka 24. II. 2012 Ronald Ortner und David Pietzka

Upload: others

Post on 19-Aug-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

InformationslogistikUnit 2: The Entity-Relationship Model

Ronald Ortner und David Pietzka

24. II. 2012

Ronald Ortner und David Pietzka

Page 2: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Outline

1 The Entity-Relationship ModelBasic NotionsRelationshipsAddenda

2 SQL

Ronald Ortner und David Pietzka

Page 3: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

Outline

1 The Entity-Relationship ModelBasic NotionsRelationshipsAddenda

2 SQL

Ronald Ortner und David Pietzka

Page 4: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions

We start with objects and relations between them:

Entity: basic objectRelation: association between several entities

Examples:Entities: Franz Huber, Ronald Ortner, his car, this course,the final exam for this course, the mark “Sehr gut”

Relations:Ronald Ortner knows Franz Huber.Ronald Ortner owns his car.Franz Huber attends this course.R.O. gives F.H. the mark “Sehr gut” for the final exam of this course.

Ronald Ortner und David Pietzka

Page 5: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions

We start with objects and relations between them:

Entity: basic objectRelation: association between several entities

Examples:Entities: Franz Huber, Ronald Ortner, his car, this course,the final exam for this course, the mark “Sehr gut”

Relations:Ronald Ortner knows Franz Huber.Ronald Ortner owns his car.Franz Huber attends this course.R.O. gives F.H. the mark “Sehr gut” for the final exam of this course.

Ronald Ortner und David Pietzka

Page 6: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions II

Abstraction of entities and relations lead to types:

Entity Type: abstraction of similar entitiesRelation Type: abstraction of similar relations

Examples:Entity types derived from entities above:

things (Ronald Ortner’s car, this course,the final exam for this course, the mark “Sehr gut” )persons (Franz Huber, Ronald Ortner)students (Franz Huber)employees of the MUL (Ronald Ortner)

Relation types derived from relations above:knowledgeownershipattendance

Ronald Ortner und David Pietzka

Page 7: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions II

Abstraction of entities and relations lead to types:

Entity Type: abstraction of similar entitiesRelation Type: abstraction of similar relations

Examples:Entity types derived from entities above:

things (Ronald Ortner’s car, this course,the final exam for this course, the mark “Sehr gut” )persons (Franz Huber, Ronald Ortner)students (Franz Huber)employees of the MUL (Ronald Ortner)

Relation types derived from relations above:knowledgeownershipattendance

Ronald Ortner und David Pietzka

Page 8: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

ER Diagrams

Entities and their relationships can be represented in an ER diagram:

Entity types are depicted as rectangles.Relationship types are depicted as diamonds.

Examples:

Ronald Ortner und David Pietzka

Page 9: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions III

Attributes are properties of either entity types or relation types:

Examples:Attributes of persons:first name, surname, birthday, nationality, ...

Attributes of cars:color, model, licence plate number, VIN, ...

Attributes of courses:course number, participants, term, ...

Attributes of attendance:date, ...

Ronald Ortner und David Pietzka

Page 10: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

The ER Model – Basic Notions III

Attributes are properties of either entity types or relation types:

Examples:Attributes of persons:first name, surname, birthday, nationality, ...

Attributes of cars:color, model, licence plate number, VIN, ...

Attributes of courses:course number, participants, term, ...

Attributes of attendance:date, ...

Ronald Ortner und David Pietzka

Page 11: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

ER Diagrams II

Attributes are depicted as ellipses in an ER diagram:Properties of entities:

Properties of relationships:

Ronald Ortner und David Pietzka

Page 12: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Basic Notions

Keys

DefinitionKey: set of attributes which uniquely determines an entityCandidate Key: minimal key (with respect to the number ofattributes→ in general not unique)Primary Key: an arbitrarily chosen candidate key

Examples:The matriculation number identifies a student.The social insurance number identifies a person.Licence plate number and country uniquely determine a car.

Ronald Ortner und David Pietzka

Page 13: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Outline

1 The Entity-Relationship ModelBasic NotionsRelationshipsAddenda

2 SQL

Ronald Ortner und David Pietzka

Page 14: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Properties

Example: property ’is an actor ’:Robert de Niro is an actor.

We say:Robert de Niro is in the set of all actors.

Generally:We may identify a property P with the set of all objects that have theproperty P:

’is an actor’ ={

x | x is an actor}

={

Robert de Niro, Brad Pitt, Tom Cruise, . . .}

Ronald Ortner und David Pietzka

Page 15: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Properties

Example: property ’is an actor ’:Robert de Niro is an actor.

We say:Robert de Niro is in the set of all actors.

Generally:We may identify a property P with the set of all objects that have theproperty P:

’is an actor’ ={

x | x is an actor}

={

Robert de Niro, Brad Pitt, Tom Cruise, . . .}

Ronald Ortner und David Pietzka

Page 16: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Properties

Example: property ’is an actor ’:Robert de Niro is an actor.

We say:Robert de Niro is in the set of all actors.

Generally:We may identify a property P with the set of all objects that have theproperty P:

’is an actor’ ={

x | x is an actor}

={

Robert de Niro, Brad Pitt, Tom Cruise, . . .}

Ronald Ortner und David Pietzka

Page 17: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Relationships

Example:relationship ’loves’:Brad Pitt loves Angelina Jolie.

We say:The tuple (Brad Pitt, Angelina Jolie) satisfies the relationship ’loves’.

Generally:We may identify a relationship R with all tuples of entities that satisfy R.→ Idea:

’loves’ ={(x , y) | x loves y

}=

{(Brad Pitt, Angelina Jolie), (Angelina Jolie, Brad Pitt),

(Tom Cruise, Tom Cruise), . . .}

Ronald Ortner und David Pietzka

Page 18: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Relationships

Example:relationship ’loves’:Brad Pitt loves Angelina Jolie.

We say:The tuple (Brad Pitt, Angelina Jolie) satisfies the relationship ’loves’.

Generally:We may identify a relationship R with all tuples of entities that satisfy R.→ Idea:

’loves’ ={(x , y) | x loves y

}=

{(Brad Pitt, Angelina Jolie), (Angelina Jolie, Brad Pitt),

(Tom Cruise, Tom Cruise), . . .}

Ronald Ortner und David Pietzka

Page 19: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Relationships

Example:relationship ’loves’:Brad Pitt loves Angelina Jolie.

We say:The tuple (Brad Pitt, Angelina Jolie) satisfies the relationship ’loves’.

Generally:We may identify a relationship R with all tuples of entities that satisfy R.→ Idea:

’loves’ ={(x , y) | x loves y

}=

{(Brad Pitt, Angelina Jolie), (Angelina Jolie, Brad Pitt),

(Tom Cruise, Tom Cruise), . . .}

Ronald Ortner und David Pietzka

Page 20: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Relationships

→ Idea:’loves’ =

{(x , y) | x loves y

}

⊆ P × P,

where × is the Cartesian product and P is the set of all persons.

Definition (relationship)A relationship R between entity types E1,E2, . . . ,Enis a subset of E1 × E2 × . . .× En.

Example:’owns’ is a subset of P ×O where O is the set of all objects.

Ronald Ortner und David Pietzka

Page 21: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Mathematical Representation of Relationships

→ Idea:’loves’ =

{(x , y) | x loves y

}⊆ P × P,

where × is the Cartesian product and P is the set of all persons.

Definition (relationship)A relationship R between entity types E1,E2, . . . ,Enis a subset of E1 × E2 × . . .× En.

Example:’owns’ is a subset of P ×O where O is the set of all objects.

Ronald Ortner und David Pietzka

Page 22: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : 1 Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : 1 Relationship)A binary relation R between entity types E1,E2 is 1 : 1, if for each entitye1 in E1 there is at most one entity e2 in E2 such that (e1,e2) ∈ Rand vice versa.

Examples: ’is married to’, ’has social insurance number’, ’hasmatriculation number’

Note: It is allowed that for an entity e1 in E1 there is no e2 in E2 with(e1,e2) ∈ R, similarly for entities e2 ∈ E2.(e.g. ’married’ is 1:1 although there are bachelors)

Ronald Ortner und David Pietzka

Page 23: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : 1 Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : 1 Relationship)A binary relation R between entity types E1,E2 is 1 : 1, if for each entitye1 in E1 there is at most one entity e2 in E2 such that (e1,e2) ∈ Rand vice versa.

Examples: ’is married to’, ’has social insurance number’, ’hasmatriculation number’

Note: It is allowed that for an entity e1 in E1 there is no e2 in E2 with(e1,e2) ∈ R, similarly for entities e2 ∈ E2.(e.g. ’married’ is 1:1 although there are bachelors)

Ronald Ortner und David Pietzka

Page 24: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : 1 Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : 1 Relationship)A binary relation R between entity types E1,E2 is 1 : 1, if for each entitye1 in E1 there is at most one entity e2 in E2 such that (e1,e2) ∈ Rand vice versa.

Examples: ’is married to’, ’has social insurance number’, ’hasmatriculation number’

Note: It is allowed that for an entity e1 in E1 there is no e2 in E2 with(e1,e2) ∈ R, similarly for entities e2 ∈ E2.(e.g. ’married’ is 1:1 although there are bachelors)

Ronald Ortner und David Pietzka

Page 25: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : N Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : N Relationship)A binary relation R between entity types E1,E2 is 1 : N, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,but for each entity e2 in E2 there is at most one entity e1 in E1 such that(e1,e2) ∈ R.

Examples: ’employs’, ’is mother of’, ’owns’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.(e.g.: unemployed, childless)

Ronald Ortner und David Pietzka

Page 26: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : N Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : N Relationship)A binary relation R between entity types E1,E2 is 1 : N, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,but for each entity e2 in E2 there is at most one entity e1 in E1 such that(e1,e2) ∈ R.

Examples: ’employs’, ’is mother of’, ’owns’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.(e.g.: unemployed, childless)

Ronald Ortner und David Pietzka

Page 27: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – 1 : N Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (1 : N Relationship)A binary relation R between entity types E1,E2 is 1 : N, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,but for each entity e2 in E2 there is at most one entity e1 in E1 such that(e1,e2) ∈ R.

Examples: ’employs’, ’is mother of’, ’owns’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.(e.g.: unemployed, childless)

Ronald Ortner und David Pietzka

Page 28: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – N : M Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (N : M Relationship)A binary relation R between entity types E1,E2 is N : M, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,and vice versa.

Examples: ’attends lecture’, ’dislikes’, ’related (by birth or marriage)’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.

Ronald Ortner und David Pietzka

Page 29: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – N : M Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (N : M Relationship)A binary relation R between entity types E1,E2 is N : M, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,and vice versa.

Examples: ’attends lecture’, ’dislikes’, ’related (by birth or marriage)’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.

Ronald Ortner und David Pietzka

Page 30: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Classification of Relation Types – N : M Relations

Binary relations between entity types E1 and E2 can be classified intothree different classes:

Definition (N : M Relationship)A binary relation R between entity types E1,E2 is N : M, if for eachentity e1 in E1 there may be several entities e2 in E2 with (e1,e2) ∈ R,and vice versa.

Examples: ’attends lecture’, ’dislikes’, ’related (by birth or marriage)’

Note: Again there may be entities in E1 (or E2) that do not ’participate’in a relationship.

Ronald Ortner und David Pietzka

Page 31: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

1 : 1 and 1 : N Relations as Partial Functions

Any 1 : 1 relationship between E1 and E2 can be considered as apartial function f : E1 → E2 and another partial function f−1 : E2 → E1.

Example: relation ’is married to’function husband : Pfemale → Pmalefunction wife: Pmale → Pfemale

Any 1 : N relationship between E1 and E2 can be considered as apartial function f : E2 → E1.

Example: relation ’is mother of’function mother : P → Pfemale

Ronald Ortner und David Pietzka

Page 32: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Generalization to n-ary Relations

For relationships between entity types E1,E2, . . . ,En this can begeneralized.Thus e.g.:

A ternary relationship between E1,E2,E3 is 1 : 1 : N iff1 : E2 × E3 → E1 is a partial function.f2 : E1 × E3 → E2 is a partial function.

Example: relation ’supervises’ between entity types professors, topics,and students is 1 : 1 : N:• Given a student and a topic there is a unique supervising professor.• Given a professor and a student there is a unique topic.

Ronald Ortner und David Pietzka

Page 33: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

Generalization to n-ary Relations

For relationships between entity types E1,E2, . . . ,En this can begeneralized.Thus e.g.:

A ternary relationship between E1,E2,E3 is 1 : N : M iff1 : E2 × E3 → E1 is a partial function.

Example: relation ’_takes an exam in_ and held by_’ between entitytypes students, lectures and professors is N : M : 1:• Given a student and a lecture there should be a unique professorwhere te student is allowed to take the exam.

Ronald Ortner und David Pietzka

Page 34: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Relationships

The (min,max)-Notation

The 1 : 1, 1 : N, and N : M characterization can be generalized to the(min,max)-notation:

For a relationship R between E1 and E2:For e1 in E1 what is the minimal number of e2 in E2with (e1,e2) ∈ R? (→ min)For e1 in E1 what is the maximal number of e2 in E2with (e1,e2) ∈ R? (→ max)

Difference to 1 : 1, 1 : N, and N : M characterization:min may be 0,max may be arbitrarily large→ max:=?.

Ronald Ortner und David Pietzka

Page 35: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Addenda

Outline

1 The Entity-Relationship ModelBasic NotionsRelationshipsAddenda

2 SQL

Ronald Ortner und David Pietzka

Page 36: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Addenda

Existence-depending Entities

Some entities may depend on the existence of other entities.Such entities are called weak.

Examples:Rooms depend on (the existence) of buildings.Exams depend on students which take them.

In ER-diagrams weak entities are represented asdouble-framed rectangles.

Ronald Ortner und David Pietzka

Page 37: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Addenda

Generalization

Similar to super- and subclasses in Java one mayabstract entity types to supertypes (→ relation ’is a’)specialize entity types to subtypes

Examples:• Member of a university is a superclass of students and universityemployees.• Professors are a subclass of university employees

In ER-diagrams one uses hexagons instead of diamonds.

Ronald Ortner und David Pietzka

Page 38: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Addenda

Generalization

Similar to super- and subclasses in Java one mayabstract entity types to supertypesspecialize entity types to subtypes

Interesting special cases of specialization:disjoint specialization:if the subclasses are disjointcomplete specialization:if the union of the subclasses gives the superclass

Ronald Ortner und David Pietzka

Page 39: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

Addenda

Aggregation

If an entity type consists of several parts,one has the special relation ’is part of’.

Note that this so-called aggregation is different from generalization.

Ronald Ortner und David Pietzka

Page 40: Informationslogistik Unit 2: The Entity-Relationship Modelinstitute.unileoben.ac.at/.../lehre/infolog/SS2012/unterlagen/unit2.pdf · The Entity-Relationship Model SQL Informationslogistik

The Entity-Relationship Model SQL

SQL-Lesson 2

Recommended Literature: MySQL Documentation, Skript Oracle IToday:String- and aggregate functions

Ronald Ortner und David Pietzka