Session 06 - Lecture 02
Session 06 - Lecture 02
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
▪ 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
9
Associative Entity
Associative Entity
Associative Entity
Associative Entity
Practices
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
NOTES: the word relation (in relational database) is NOT the same as the word
relationship (in ER model)
18
Remind: Relational Database
19
Mapping ER diagrams into relations
20
Mapping regular entities to relations
21
Mapping regular entities to relations
Composite
attribute
22
Mapping regular entities to relations
▪ 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
Foreign key
Foreign key
27
Exercise
28
Mapping associative entities
Identifier assigned :
▪ The assigned identifier becomes primary key
29
Mapping associative entities
Identifier attribute
30
Mapping associative entities
Identifier becomes
primary key
31
Mapping associative entities
32
Mapping associative entities
33
Mapping unary relationships
▪ One – to – Many & One – to – One : Recursive foreign key in the same
relation.
34
Mapping unary relationships
35
Mapping unary relationships
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
38
Exercise
39
SQL for Data Analytics