0% found this document useful (0 votes)
2 views41 pages

Session 06 - Lecture 02

The document provides an introduction to data modeling in database management systems, emphasizing the importance of accurately representing data objects and their relationships. It outlines the processes for designing a database at conceptual, logical, and physical levels, including mapping entity-relationship diagrams to relational structures. Key concepts such as primary and foreign keys, as well as various relationship mappings, are discussed to aid in effective database design.

Uploaded by

k62.2314570009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views41 pages

Session 06 - Lecture 02

The document provides an introduction to data modeling in database management systems, emphasizing the importance of accurately representing data objects and their relationships. It outlines the processes for designing a database at conceptual, logical, and physical levels, including mapping entity-relationship diagrams to relational structures. Key concepts such as primary and foreign keys, as well as various relationship mappings, are discussed to aid in effective database design.

Uploaded by

k62.2314570009
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 41

Data Science for Economics and Business

DATABASE MANAGEMENT SYSTEM


Course Introduction

Lecture 2: Introduction data modeling


Database Design

Section 1: Data Modeling


Data Modeling

Data modeling is the process of creating a data model for the data to be stored in a
Database:
▪ Emphasize on what data is needed and how it should be store.
▪ Visualize representation of data and enforces business rules, compliances and
policies on the data.
▪ Ensure the consistency in naming conventions, default values, semantics, security
while ensuring quality of the data.

4
Data Modeling

Why use Data modeling?

▪ Ensure that all data objects required by the database are accurately represented
▪ Help to design the database in conceptual, logical and physical levels
▪ Help to present the relations between tables
▪ Provide a clear picture about the DB that helps Developer create physical DB
▪ Help to identify missing and redundant data
▪ Help IT to upgrade and maintain DB faster and cheaper

5
Process to design a good database​

6
Process to design a good database​

7
Three levels of Data Modeling

8
Conceptual Data Model

▪ Entity
▪ Attribute
▪ Relationship:
• Relationship type
• Relationship cardinality

An example of Conceptual Data Model

9
Associative Entity
Associative Entity
Associative Entity
Associative Entity
Practices

Convert the relationship to associate entity


Answer
Database Design

Section 2: Mapping ER to Relations


Logical design

Conceptual design
▪ Understand the data storage and access requirement
▪ No direct relationship with database technologies

Logical design
▪ Maps the conceptual requirements into the data model associated with a
specific database management system.
▪ We focus on Relational data modeling.

17
Correspondence with ER Model

▪ Relations (tables) correspond to entity types

▪ Rows correspond to entity instances

▪ Columns correspond to attributes.

NOTES: the word relation (in relational database) is NOT the same as the word
relationship (in ER model)

18
Remind: Relational Database

Primary key : an attribute (or a combination of attributes) that can uniquely


identify each row in a relation
▪ Simple primary key (single field)
▪ Composite primary key (multiple fields)

Foreign key : an attribute (or combination of attributes) in a relation that is primary


key to another relation.

19
Mapping ER diagrams into relations

Mapping ER to Database Objects:


1. Mapping regular entities to relations
2. Mapping binary relationships
3. Mapping associative entities
4. Mapping unary relationships
5. Mapping ternary relationship

20
Mapping regular entities to relations

Mapping regular entities to relations


▪ Simple attributes: ER attributes map directly onto the relation

▪ Composite attributes: Use only their simple, component attributes

▪ Multi-valued attributes: each attribute becomes a separate relation with a foreign


key taken from the superior entity

21
Mapping regular entities to relations

CUSTOMER entity type with simple attributes -> CUSTOMER relation

CUSTOMER entity type with composite attributes

Composite
attribute

22
Mapping regular entities to relations

CUSTOMER entity type with multi-valued attributes

▪ Multi-valued attribute becomes a separate


Multi-valued attribute
relation with foreign key
▪ 1 – to – many relationship between EMPLOYEE
and EMPLOYEE_SKILL
23
Mapping binary relationships

▪ One – to – Many : primary key on the one side becomes a foreign key on
the many side
▪ Many – to – Many : create a new relation with the primary keys of the two
entities as its primary key.
▪ One – to – One : primary key on the mandatory side becomes a foreign key
on the optional side

24
Mapping binary relationships

One – to – Many

Foreign key

25
Mapping binary relationships

One – to – One

Foreign key

26
Mapping binary relationships

Many – to – Many

Composite primary key

Foreign key

Foreign key

27
Exercise

Translate E-R diagram to Relation

28
Mapping associative entities

Identifier not assigned :


▪ Default primary key for the association relation is composed of the primary
keys of the two entities (as in many-to-many relationship)

Identifier assigned :
▪ The assigned identifier becomes primary key

29
Mapping associative entities

SHIPMENT associative entity with identifier attribute

Identifier attribute

30
Mapping associative entities

SHIPMENT associative entity with identifier attribute

Identifier becomes
primary key

31
Mapping associative entities

ORDER_LINE associative entity without identifier attribute

32
Mapping associative entities

ORDER_LINE associative entity without identifier attribute

primary key is composed


of the primary keys of
the two entities

33
Mapping unary relationships

▪ One – to – Many & One – to – One : Recursive foreign key in the same
relation.

▪ Many – to – Many : two relations


o One for the entity type
o One for an associative relation in which the primary key has two attributes,
both taken from the primary key of the entity.

34
Mapping unary relationships

One – to – Many relationship

35
Mapping unary relationships

Many – to – Many relationship

36
Mapping ternary (and n-ary) relationships

▪ One relation for each entity and one for the associative entity
▪ Associative entity has foreign keys to each entity in the relationship

For example: How could you transform this ternary relationship to relation ?

37
Mapping ternary (and n-ary) relationships

We need Treatment_Date and Treatment_Time in composite primary key because


same patient can visit the same physician multiple time at multiple date

38
Exercise

A university might need to record which teachers taught which subjects


in which courses

Please translate E-R diagram to Relation

39
SQL for Data Analytics

It’s time for your questions


THANK YOU !

You might also like