Title: Data Modelling
1Data Modelling
Entities, Attributes and Relationships
2Data Modelling
- Technique for describing information structures
- Information models represent
- things - entities
- properties of things - attributes
- associations between things - relationships
3Entities
- Abstractions of real world things
- e.g. CUSTOMER
- does not relate to specific customers
- ...any distinguishable person, place, thing,
event or concept about which information is kept.
(Bruce 1992)
Specific customer
4Attributes
- The elements of data belonging to an entity are
known as its attributes
A/C No. Name Address Tel No. Credit limit
Customer
5Relationships
- Imagine two entities
- Lecturer and Student
- Lecturers teach students
- Teaching is the relationship between the two
abstract entities
6Logical Data Model
An Entity Type has a set of attributes e.g.
Customer has attributes of Account Number Name
Address Telephone Number Credit Limit
7Logical Data Model
An Entity Type may have a number of
occurrences. Each Entity Occurrence has a unique
set of values for the attributes.
A/C No. Name Address Tel No. Credit limit
Customer Entity Type
Customer Entity Occurrences
8Logical Data Model
Customer Entity Attribute Value Account
Number BL032 Name Bloggs Son Address 117
Acacia Rd Birmingham 7 Telephone Number 0121
345678 Credit Limit 2500
9A Table or Relation
Each row of the table is unique.
10Entities, Tables Relations
- An Entity Type is represented as a Table
(Relation) - Each Row (Tuple) of the Table is an Occurrence of
the Entity - Each Column (Domain) of the Table contains the
Values of one Attribute of the Entity
11Physical Data Organisation
- An Entity Type is usually implemented as a File
in the Physical Storage Medium - Each Entity Occurrence is a Record in the File
- The Value of an Attribute of the Entity
Occurrence is stored in a Field within the Record
12Physical Organisation
physical medium
file
field
record
13Repeating Attributes / Fields
Order File / Entity
Are repeating attributes (fields) really
attributes of this entity?
14Attributes / Fields of an Order
15Entities or Attributes?
When is data an Attribute of an Entity and when
is it a separate Entity? Can one Entity ever be
considered to be simply Attributes of another?
16Diagrammatic Representation
17Diagrammatic Representation
Relationship between entities
master
one order can be for many items
crows foot
detail
18Degrees of Relationship
19Optional Relationships
An Order must be for a Customer
but a Customer may not have any orders
optional at the customer end
20Consultant System
- A Client has an Account
- Consultants have a Grade and a number of Skills
- Consultants are active on various Projects
- Each Project is for one Account
21Possible Entities for Consultant System
22Initial Attempt at Relationships
23Resolving One to One Relationships
A Client can only have one Account.
Client
Account
The account is an attribute of the client and NOT
a separate entity. Simply merge the entities
which have a one to one relationship.
24One to one relationships resolved
25Resolving Many to Many Relationships
Difficult to implement so how can they be
replaced?
What is the nature of the relationship between an
Actor and a Scene?
26Resolving Many to Many Relationships
Create a linking entity which is a detail to both
the original entities.
Actor and Scene are both masters to the new
linking entity of Appearance.
27Resolving Many to Many Relationships
What would make suitable entities and what
attributes might they have?
28Many to many relationships resolved
Avoid crossed relationships Resuscitate dead
crows!
29Developing a Logical Data Structure
- identify possible entities
- draw initial entity relationship diagram
- resolve 11 and manymany relationships check
for further entities and relationships - remove redundant relationships
- show optionality
30Cross-checking the LDS
The LDS is derived using a Top Down
approach. It can be cross-checked by using a
Bottom Up approach, building up the entities
from their attributes. This technique is called
Normalisation which is the subject of the next
lecture.
31Relational Data Analysis
With thanks to Codd Date.
32Attributes / Fields of an Order
33Normalisationobjectives
- to reduce data redundancy
- to hold each data item (attribute) with as few
occurrences as possible - to identify and remove any dependencies between
data items stored together (in the same table)
34A RelationA two-dimensional table
35A Compound Key
36Attributes Listed
37Un-Normalised Data
38Assumptions
- Consultant No., Skill Code and Grade are unique.
- A consultant can have many skills each identified
by a Skill Code. - For each skill only the consultants highest
Qualification is recorded. - Other consultants may have the same skills (and
Skill Code) but not necessarily the same
Qualification. - Each Skill Code has one Description.
- Each Grade belongs to one Salary Scale.
39Un-Normalised Form (UNF)
40 UNF
- list all data attributes
- allocate primary key
- identify repeating group(s)
- (optional)
41First Normal Form (1 NF)Rule
remove repeating data
Consultant No. Name Address Grade Salary
Scale Skill Code Description Qualification
42First Normal Form (1 NF)
43 1NF
- separate repeating group
- copy non-repeating group unchanged
- add initial primary key to repeating group
identify compound key
44Second Normal Form (2 NF)Rule
remove part-key dependencies
Consultant No. Skill Code Description Qualificatio
n
45Second Normal Form (2 NF)
46 2NF
- separate part-key dependencies
- all other groups are copied across unchanged
- do not omit key only groups
47Third Normal Form (3 NF)Rule
remove inter-data (and inter-key) dependencies
Consultant No. Name Address Grade Salary Scale
48Inter-Data Dependency
49Third Normal Form (3 NF)
50 3NF
- separate inter-data (non-key) dependencies
- identify foreign keys
51Normalisation of Consultant Data
52Normalisation Stages
- UNF - list attributes allocate primary key
- 1NF - remove repeating groups
- 2NF - remove part key dependencies
- 3NF - remove inter-data dependencies
53Third Normal Form Tests
- Given a value for the key of a 3NF relation, is
there only one possible occurrence of the
associated data (row)? - Is each attribute (column) of the relation
dependent on the key, the whole key and nothing
but the key?
54Relation (Table) Names
55Summary of the Normalisation
563NF Entity-Relationship Diagram
- 3NF Relations are Entities
- Entities / Relations are linked by their common
attributes - Relational Model
57Relationships from 3NF
- Entities are linked by their keys
- Keys and Foreign Keys are the common attributes.
- An Entity / Relation with a Compound Key is a
Detail - Its Masters are Relations that have as their Key
a part of the Compound Key - An Entity / Relation with a Foreign Key is a
Detail - Its Master is the Relation which has the Foreign
Key as its whole Key
583NF Relations are Entities
59Compound Keys are Details
60Foreign Keys are Details
61Cross-checking the LDS
The LDS is derived using a Top Down
approach. Normalisation is used to cross-check
the LDS by using a Bottom Up approach, building
up the entities and relationships from their
attributes.
62Compare to LDS
63LDS versus 3NF Entity Relationship Diagram
- Why are the diagrams not the same?
- What do they have in common?
- What are the differences? Why?
- What do we need to resolve the differences?
- Normalise other documents / data sources.
64What is the key?
Activity No
Time (days)
Activity Type
Consultant No
Project No
write letter draw DFD interview plan
project visit site
003 001 004 004 002
0.1 1.5 0.3 2.0 1.0
1 2 1 2 1
C232 C232 C979 C979 A176
Activity No. is only unique within one project.
65A Composite Key
66Data Modelling
- Derive an LDS - top down
- Normalise all relevant data (documents etc.)
- apply 3NF tests
- Merge relations with the same key
- check for synonyms and homonyms
- apply 3NF tests again
- Give each Relation (Entity) a name
- names should be consistent with LDS
- Draw a 3NF Entity Relationship Diagram
- Compare LDS 3NF ERD and resolve differences
67Another Normalisation
68Normalisation of Purchase Order
69Purchase Order Document 3NF
- apply 3NF tests
- name entities (relations)
70Sales Order
Date Required
Part No
Item
1
19/2/99
41235
2
19/2/99
23467
3
19/2/99
89965
assembly
4
23467
3.20
32.00
26/3/99
Order Total 58.00
Assumptions Customer No, Order No and Part No
are unique but Item is only unique within one
order. Price each depends on Part No.. The same
Part No can be used for more then one Item on the
same order (but the Date Required will vary).
71Normalisation of Sales Order
3NF
Sales Order No. Date Customer No. Order
Total Customer No. Name Sales Order
No. Item Part No. Quantity Value Date
Required Part No. Description Price each
)
(
72Sales Order Document 3NF
73Merged 3NFs
743NF Relations are Entities
75Compound Keys are Details
master Part No.
master Purchase Order No.
76Foreign Keys are Details
Sales Order No. is foreign key
77LDS from Tutorial Example
78LDS versus 3NF Entity Relationship Diagram
- What are the differences?
- What do we need to resolve these?
- Normalise a despatch document.