Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship...

18
Database R.Fröhlich, M. Schaffer, J. Konicek R. Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model

Transcript of Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship...

Page 1: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

Different

Relationship Types in a

Logical Relational Model

Page 2: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1. Entity Types1.1 Entity

1.1 Strong and Weak Entity

1.2 Representing Weak Entity

2. Binary Relationship Types2.1 One-to-One Relationship

2.2 One-to-Many Relationship

2.3 Many-to-Many Relationship

2.4 Problem with Recursive Relationship

2.5 Other Problems for Relational Models

Topics

Page 3: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1. Entity Types1.1 Entity

1.1 Strong and Weak Entity

1.2 Representing Weak Entity

2. Binary Relationship Types2.1 One-to-One Relationship

2.2 One-to-Many Relationship

2.3 Many-to-Many Relationship

2.4 Problem with Recursive Relationship

2.5 Other Problems for Relational Models

Topics

Page 4: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1.1 Entity

•An entity is an object that exists and is distinguishable from other objects

Example: specific person, company, event plant

• Entities have attributes Example: people have names and adresses

• An entity set is a set of entities of the same type that share the same properties.

Example: set of all persons, companies, trees, holidays

•An entity is an object that exists and is distinguishable from other objects

Example: specific person, company, event plant

• Entities have attributes Example: people have names and adresses

• An entity set is a set of entities of the same type that share the same properties.

Example: set of all persons, companies, trees, holidays

Page 5: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1.1 Example for Entity

name positon salary

Froehlich Controller 2500€

Schaffer Sales 2500€

Konicek Purchase 2000€

Employeename phone

Froehlich 505

Schaffer 402

Konicek 308

NewOfKin

Employee

name salaryposition

NewOfKin

name phone

Page 6: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1.2 Strong and Weak Entity Types

• Create a relation that includes all simple attributes of that entity. • Has sufficient attributes to form a primary key is called a strong entity.

EntityEntityStrong EntityStrong Entity Weak EntityWeak Entity

• Lacks sufficient attributes to form a primary key.• A weak entity is an entity that exists only if is related to a set of uniquely determined entities, which are called the owners of the weak entity.

A strong entity set is a

dominant entity A weak entity set is a subordinate entity

Page 7: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1.3 Representing Weak Entity

• But every entity needs a key: What to do?

- Must import attributes from strong entity set(s)- Importation is done via many-to-one relationship(s)- A weak entity set member is subordinate to the dominant entity(-ies) from strong entity set(s) providing (reliably) attributes to complete its key

1 n

The idea of strong and weak entity sets is related to the existence dependencies seen earlier.

Page 8: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1. Entity Types1.1 Entity

1.1 Strong and Weak Entity

1.2 Representing Weak Entity

2. Binary Relationship Types2.1 One-to-One Relationship

2.2 One-to-Many Relationship

2.3 Many-to-Many Relationship

2.4 Problem with Recursive Relationship

2.5 Other Problems for Relational Models

Topics

Page 9: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

1 : 1One-to-One Entity BEntity BEntity AEntity A

N : MMany-to-

ManyEntity BEntity B

1 : NOne-to-Many Entity BEntity B

2. Binary Relationship Types

Entity AEntity A

Entity AEntity A

Page 10: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.1 One-to-One Binary Relationship Types

Each employee has one or none locker

One locker is owned by one employee

0..1 1..1LOCKER EMPLOYEE1:1

• A 1:1 relationship cannot be used to identify parent and child entities in a relationship.

Page 11: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.1 One-to-One Binary Relationship Types

• The key from one relation is placed in the other as a foreign key.• It does not matter which table receives the foreign key.

Foreign Key

LOCKER EMPLOYEE1:1

Emp_ID

Locker_ID

Locker_ID

Emp_ID

Locker_Desc

Location

Primary Key

Foreign Key

Primary Key

EmpName

Page 12: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.2 One-to-Many Binary Relationship Types

Each employee is employed in only one Department

Each department employs one ore more

employees

1..1 1..NDEPARTMENT EMPLOYEE1:N

• Entity on the ‘1..1 side‘ is designated the parent entity and entity on the ‘1..N side‘ is the child entity.

Page 13: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.2 One-to-Many Binary Relationship Types

• Like a 1:1 relationship, a 1:N relationship is saved by placing the key from one table into another as a foreign key• However, in a 1:N the foreign key always goes into the ‘1..N side’

Foreign Key

DEPARTMENT EMPLOYEE1:N

Emp_ID

Emp_Name

Dep_ID

Dep_Address

Dep_Phone

Primary Key

Dep_ID

Page 14: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.3 Many-to-Many Binary Relationship Types

Each employee has one or more skills

Each skill is “owned“ by one or

more employees

1..* 1..*SKILL EMPLOYEEN:M

Page 15: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.3 N:M ->: not capable with Rel. Model

IdentifiesDescribes EMP_Skill

Skill_ID

Emp_ID

• To save a N:M relationship, a new relation has to be created: the intersection relation

SKILL EMPLOYEEN:M

Skill_ID Emp_ID

Skill_Desc Emp_Name

1..1

1..1

1..n 1..n

Page 16: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.4 Problem with Recursive Relationships

TeamMember

N:M

SUPPORTER

SUPORTEE

Supports0..*

0..*

TeamMember Support

Supports

Supported by

1..1

1..1

0..*

0..*

Page 17: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

2.5 Other Problems for Relational Models

Complex relationship types have to be removed

Solution: Create new relation

Foreign keys: Primary keys of the participated entities

Primary key: Foreign keys that represent a many (1..*,0..*) relationship + perhaps other attributes of new relation

Multi-valued attributes (mva) aren‘t allowed

Solution: Create new relation

Primary key: Combination of mva and primary key of the related entity

Page 18: Database R.Fröhlich, M. Schaffer, J. Konicek Database Relationship Types Different Relationship Types in a Logical Relational Model.

Database

R.Fröhlich, M. Schaffer, J. KonicekR. Fröhlich, M. Schaffer, J. Konicek

DatabaseRelationship Types

THE ENDThank you for attention !