You are on page 1of 44

Data modeling

Pr. Amos DAVID


LORIA, FRANCE

Data modeling ; UI Ibadan ;


August 2004 ; Prof. Amos DAVID 1
Content
„ Why data modeling ?
„ Entity-Relation model
„ Relational model

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 2


Why data modeling ?
„ Represent the real world
„ Represent only the necessary elements
„ Focus on the use of the elements
„ Represent the relationships between the
selected elements

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 3


Why data modeling ? …
„ For efficient computerization
„ Reduce data redundancy
„ Disk space problem
„ Volume of data transfer

„ Guaranty data integrity


„ Valid information irrespective of context
„ Student information in the department and at the admission office

„ Objects of documentation
„ Describe the computed elements – user notice – technical
notice
„ For the programmer
„ For the system designer
„ For the end-users

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 4


Examples
„ Admission office
„ STUDENT (N°, names, marital status, sex, degree, address)

„ The department
„ STUDENT (N°, names, courses, address)

„ The administrative office


„ PERSONNEL (N°, names, marital status, faculty, department, address)

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 5


Entity-Relation model
„ Represent the real world elements with four
main concepts
„ Entity
„ Attributes
„ Relation
„ Cardinality

„ Employs graphic representation


„ Intuitive approach

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 6


Entity
„ The basic conceptual or real element
„ Examples
„ A student
„ A personnel
„ A town

„ Entities have real existence (the instances)


„ They are identifiable
„ Amos DAVID
„ Charles ROBERT
„ Ibadan

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 7


Entity …
„ Each entity is associated with a set of
attributes
„ The instances of an entity have the
same characteristics
„ They have the same set of attributes
„ For example
„ All the students have the same set of attributes
„ All the members of staff have the same set of
attributes

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 8


Attributes
„ Attributes are used for describing the entities
„ The entities and their attributes are determined
according to the database project
„ Taking into account the functions to be accomplished
„ Examples
„ Represent students at the department for course registration
„ Represents members of staff for salaries and promotions

„ One of the attributes must be an IDENTIFIER


„ Its value is unique for each entity

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 9


Attributes …
„ How to reduce redundancy
„ Avoid structured attributes
„ Structured attributes should be dissociated
„ Example
„ Names
„ First name, last name
„ Address
„ Street n°, street name, town, local government, state

„ Dissociating structured attributes allows an easy access to the


component elements
„ Example
„ The town element of an address can be easily extracted instead of
performing string extraction on the structured element

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 10


Attributes …
„ Examples …
„ Name, Address
„ Amos DAVID; Dept computer science, UI Ibadan, Ibadan, Oyo
state
„ Olu OJO; 23 Aderemo street, Agbowo, Agbowo LGA, Ibadan,
Oyo state
„ Uche KALU; 5 market road, Anambra, Anambra state

„ Problems with this representation


„ The addresses do not have the same number of elements, so
how can one obtain a specific component ?
„ The nth element ?
„ Starting from the nth character ?
„ How can one locate the town within an address ?

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 11


Attributes …
„ Examples …
„ Dissociate structured elements
„ Name, Street number, Street name, Town, Local government, State
„ Amos DAVID; Dept computer science; UI Ibadan; Ibadan; ;Oyo state
„ Olu OJO; 23; Aderemo street; Agbowo; Ibadan; ; Oyo state
„ Uche KALU; 5; market road; Anambra; ; Anambra state

„ Efficiency
„ Each entry has the same number of elements
„ A component element can be easily extracted using its position

„ Example
„ The town value is always at the 4th position
„ The state value is always at the last position
„ The position can be in string functions or for the colon numbers in tables

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 12


Attributes
reducing redundancy …
„ Avoid attributes whose value is a list ;
a new entity should be created
„ Example (memory redundancy)
„ Courses as attribute of Degree
„ We do not know the number of courses for a

degree
„ Create DEGREE and COURSE

„ Associate the two entities

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 13


„ Example (memory redundancy) …
„ Computer science, course 1, course 2, course 3
„ Biology, course 3, course 6, course 7, course 20
„ Chemistry, course 7, course 3, course 8, course 9, course 10

„ In terms of memory allocation, how many courses should be


anticipated ?

„ Because of the unknown number of courses, the anticipated


number will either be too few or too many

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 14


Attributes …
„ How to ensure data integrity
„ Identify the “functional dependency” of attributes
„ Example
„ A town belongs to only one state
„ Towns are unique

„ In a case of functional dependency, use a new


entity to regroup the dependent attributes
„ Create a relation between the new entity and the
original one

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 15


Attributes …
„ Examples …

„ Name, Street number, Street name, Town, Local government, State

1. Amos DAVID; Dept computer science; UI Ibadan; Ibadan; Oyo state


2. Olu OJO; 23; Aderemo street; Agbowo; Ibadan; Oyo state
3. Uche KALU; 5; market road, Anambra; ; Anambra state

„ Entities 1 and 2 are redundant, prone to non integrity


„ Should a town change from one state to another, all the entities are no
longer valid
„ All the entities must be modified
„ Entering entity 1 and 2 (town, state) two times may produce typographical
error

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 16


Entity – graphic representation
„ A rectangle divided into two parts
„ The name of the entity in the upper part
„ The names of the attributes at the lower part
„ The identifier is underlined

PERSON TOWN
Number Town name
Last name State
First name Local government
Date of birth

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 17


Relation
„ A relation specifies the association between
two or more entities
„ Example
„ Town and Person

„ The relation should specify the semantic of


the association
„ A person lives in a town

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 18


Relation …
„ A relation is symbolized by an oval with its semantic inside the oval
„ A relation is further specified by cardinalities that indicate the number
of associated instances
„ Example
„ A person lives in a minimum of one town and in a maximum of 1 town
„ A town is inhabited by a minimum of one person and a maximum of n (indicating
several)

PERSON TOWN
Number (1,n) Name
Last name Lives in Surface area
First name (1,1) State
Date of birth Local government

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 19


Relation …
„ A relation may sometimes have an attribute
„ The attribute describes the relation and not the
entities associated
„ Example
„ The number of an article bought by a client as well as
the date are neither an attribute of the client nor that of
the article, but an attribute of the association

„ The attributes of the relation are indicated at


the lower part of the oval that represents the
relation
Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 20
Relation …
„ Example

CLIENT ARTICLE
Number (1,m) Name
Last name Bought Unit price
First name (1,n) Quantity
Date
Date of birth

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 21


Relation …
„ Maximum cardinality
„ This indicates the maximum cardinalities
on the left and on the right of a relation
„ Example
PERSON [1:n] TOWN
Number (1,n) Name
Last name Lives in Surface area
First name (1,1) Stage
Date of birth Local government

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 22


Relation …
„ How to read the relations : recall
„ A person lives in a minimum of 1 town and in a maximum of
1 town
„ A town is inhabited (is lived) by a minimum of one person
and a maximum of n person (several)

PERSON TOWN
Number (1,n) Name
Last name Lives in Surface area
First name (1,1) Stage
Date of birth Local government

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 23


REMARKS
„ The entity and the association as described above
correspond to the description of the concepts. In the
literature, they are termed entity-type and relation-
type. Their instantiations (existence) are termed
entity and relation.

„ For us we use entity and entity-type ; relation and


relation-type indifferently.

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 24


Relational model

Data modeling ; UI Ibadan ;


August 2004 ; Prof. Amos DAVID 25
Relational model
„ The basic concepts
„ Table
„ Domain
„ Attribute
„ Key
„ N-uplet

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 26


A table
Relation
Student Attributes

Last name First name Date of birth Degree


The N-Uplets

Domain (same types of value : names)


names
Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 27
Domain
„ Represents the data type of a column
„ It is defined by a closed list or by formal
specification
„ Example
„ Town : {Oyo, Ibadan, Lagos}
„ Town : Alphabetic characters
„ Age : Integer value

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 28


Attribute
„ An attribute specifies a particular column

„ Each column must be distinguished from the others


„ Two columns should not have the same name

„ Two attributes may have the same domain


„ Example
„ First name, Last name : NAMES

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 29


N-uplet
„ A line of the table
„ Also called a record
„ It is a Cartesian product of attributes

„ Example
„ Amos, David
„ John, Olaoye

„ From the two attributes


„ A1, A2

„ From domains
„ Name, Name

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 30


Key
„ A key is the minimum set of attributes of a relation whose
values are distinct for each n-uplet

„ Example
„ First name, Last name

„ Non of the attributes can be used as key


„ The two attributes combined can not serve as key neither

„ Reasons
„ Two people may have the same name
„ Two people may have the same first and last name

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 31


Key …
„ Examples
„ Student N°, first name, last name
„ The Student N°, first name combined can be used as key, but only

the Student N° is sufficient

„ N° student, first name, last name, email


„ Either Student N° or email can be used as key

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 32


From ERM to RM
1. To each entity corresponds a relation
(Entity name · relation name)
2. To each attribute of an entity corresponds an attribute of the relation
3. The identifier of the entity becomes the key of the relation
4. For associations of maximum cardinality [1:n], add the key of the
relation on the n side to the relation on the 1 side
5. For associations of maximum cardinality [n:m], a new relation should
be created using the concatenation of the keys of the associated
relations as the key. The attributes of the relation should be added
as attributes of the new relation.

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 33


REMARKS
„ A collection of relations obtained from an entity-
relation model as described above will have the
following characteristics
„ Each attribute is single-value
„ The key contains the least number of attributes
„ There are no dependencies between the attributes

„ A collection of relations that have the above


characteristics are considered of 3rd normal form

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 34


Practical
„ Model the following types of person in
the university
„ the students
„ the members of staff

„ Be sure to apply the methods for


reducing redundancy and guaranteeing
data integrity

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 35


Practical : University students
„ Description
„ Each student has a number, a name, an address
„ A student is registered for a degree
„ A student may not register for more than one degree
simultaneously
„ A student may take several degrees from the university
„ To a degree is associated a set of courses
„ A degree is managed by a department
„ A course is offered by only one department

„ Example of questions
„ What are the courses associated with a degree ?
„ What are the courses taken by a student for a degree ?
„ What are the courses offered by a department ?

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 36


Project
„ Propose an entity relation model as well as
the associated relational model for articles
and clients in order to produce a receipt.
„ A client can buy one or more articles
„ An article can be bought by zero or many
clients
„ Each article has a unique number and a name
„ Each article has a name and a price
„ A client has a number and a name

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 37


Students ER model
[1:m]
DEGREE (1,1)
(1,m) Name
STUDENT
Offered by

First name
Last name Register
(1,m) (1,m)
Day of birth (1,n) Year
Month of birth [n: m]
Year of birth Necessary for
[n: m] DEPARTMENT
Name
Faculty
(1,n)
COURSE
Code
Name
Credit

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 38


Students relational model

DEGREE (DegreeName, DepartmentName,)

STUDENT (StudentN°, First name, Last name, Day of birth, Month of birth, Year of birth)

DEPARTMENT (DepartmentName, Faculty)

COURSE (CourseCode, Name, Credit)


Register (StudentN°, Degree Name, Year)

Necessary for (CourseCode, DegreeName)

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 39


Database
„ A collection of relations
„ Represented as tables
„ The links between the relations are
materialized either automatically or
explicitly during query formulation

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 40


Querying a database
„ Querying a database allows the user to
extract data from the database
„ One of the most common querying
language is SQL
(Standard Query Language)

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 41


SQL
„ The syntax is as follows
„ SELECT colons FROM tables WHERE conditions

„ Example
„ SELECT Students N°, Student Name FROM Students
„ Join two tables : Students and Register
„ Select the n-uplets where Student N° in Register =
Student N° in Student
„ SELECT Student N°, Student Name FROM Students,
Register WHERE Degree Name = “Computer Science”

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 42


SQL : remarks
„ SQL as indicated above provides a
Cartesian product from the tables

„ In order to reduce multiple n-uplets, a


UNIQUE function is applied
„ SELECT UNIQUE colons FROM tables
WHERE conditions

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 43


Functions applicable to SQL
„ Count the number of distinct n-uplets
„ Sort and group n-uplets
„ Sum the values of a particular colon

Data modeling ; UI Ibadan ; August 2004 ; Prof. Amos DAVID 44

You might also like