Chapter 2 Data Models
Chapter 2 Data Models
Data Models
DATA MODELLING OVERVIEW
▪ Database Design focuses on how the database structure will be used to store and
manage end-user data.
What is Data Modelling?
▪ On the other hand, Data Modelling is the first step in designing a database and
refers to the process of creating a specific data model for a determined
problem domain.
What is a Data Model?
▪ A data model is a conceptual representation of the data structures that are
required by a database. The data structures include:
▪ data objects
▪ the associations between data objects
▪ the rules which govern operations on the objects.
DATA MODELLING OVERVIEW
▪ A data model is a relatively simple representation, usually graphical, of
more complex real-world data structures.
▪ The data model focuses on:
▪ what data is required
▪ how it should be organized
▪
▪
▪
▪
CONSTRAINTS
▪ A constraint is a restriction or rule placed on the data. Constraints are important
because they help to ensure data integrity. Constraints are normally
expressed in the form of rules.
▪ They can apply to a column, a whole table, more than one table or an entire
schema.
▪ The schema is the conceptual organization of the entire database. There are
there are mainly three types of schemas:
▪ External Schema - database users’ view
▪ Conceptual Schema - database administrators’ view
▪ Internal Schema - database developers’ view
▪ The internal schema is composed of the physical schema and the logical
schema.
CONSTRAINTS
▪ Five Types of Constraints:
▪ NOT NULL: value in a column must not be NULL.
▪ UNIQUE: value(s) in specified column(s) must be unique for each row in a table.
This constraint ensures that each rows for a column must have different value.
▪ PRIMARY KEY: combination of a NOT NULL and a UNIQUE constraint. value(s)
in specified column(s) must be unique for each row in a table and not be NULL;
normally each table in a database should have a primary key - it is used to
identify individual records.
▪ FOREIGN KEY: ensure the referential integrity of the data and value(s) in
specified column(s) must reference an existing record in another table (via
primary key or unique constraint). Referential integrity means that if the
foreign key contains a value, that value refers to an existing valid tuple (row) in
another relation
▪ CHECK: ensures that the value stored in a column meets a specific condition.
BUSINESS RULES
▪ From a database point of view, the collection of data becomes
meaningful only when it reflects properly defined business rules.
▪ A business rule is a brief, precise, and unambiguous description of a
policy, procedure, or principle within a specific organization.
▪ Business rules apply to any organization that stores and uses data to
generate information.
▪ Business rules help to create and enforce actions within any
organization’s environment.
▪ Properly written business rules are used to define entities, attributes,
relationships, and constraints.
BUSINESS RULES
▪ Business rules can apply to people, processes, corporate behavior and computing
systems in an organization, and are put in place to help the organization achieve its
goals.
▪ Data can be considered significant only after business rules are defined, without them
the data is just records. However, to a business they are the characteristics that are
defined and seen by the company.
▪ To be considered true, business rules must be in writing and kept up to date.
▪ Sources of business rules are: managers, policy makers, department managers,
written documentation, procedures, standards, operation manuals, and interviews
with end-users.
▪ Business Rules give the proper classification of entities, attributes, relationships, and
constraints.
BUSINESS RULES
▪ As a general rule in database design, the noun in a business rule will translate into an entity in
the model and a verb (active or passive) associating nouns will translate into a relationship
among the entities.
▪ Business rules should be considered as bidirectional. There are two questions to ask to properly
identify a relationship in a business rules:
▪ How many instances of B are related to one instance of A?
▪ How many instances of A are related to one instance of B?
▪ There are several protocols to the way business rules are written. Not every protocol has to be
followed.
CHARACTERISTICS OF BUSINESS RULES
▪ Business rules are brief, precise, and unambiguous descriptions of a policies,
procedures, or principles within a specific organization
▪ They apply to any organization that stores and uses data to generate
information
▪ They are description of operations that help to create and enforce actions within that
organization’s environment
▪ They must be rendered in writing
▪ They must be kept up to date
▪ Sometimes they are external to the organization
▪ They must be easy to understand and widely disseminated
▪ They describe characteristics of the data as viewed by the company
IMPORTANCE OF BUSINESS RULES
▪ Business rules promote the creation of an accurate data model.
▪ They help standardize the company’s view of data.
▪ They can be a communication tool between users and designers.
▪ They allow the designer to:
▪ understand the nature, role, and scope of the data
▪ understand business processes
▪ develop appropriate relationship participation rules
▪ identify all constraints
▪ create an accurate data model.
EXAMPLES OF BUSINESS RULES
▪ Suppose there was a single company responsible for handling student
applications to different universities and it had the following
business rules:
▪ Each student can submit one application per university.
▪ Each application is submitted by only one student.
▪ Each university can be associated with one or more applications and each
application is associated with only one university
▪ Each application must include two or more recommendations and each
recommendation is included with only one application.
▪ From the above business rules identify all the entities and relationships
among the entities and draw a relational data model that include:
▪ All the entities
▪ At least three (3) attributes for each entity
▪ All the relationships among the entities
EVOLUTION OF DATA MODELS
▪ Hierarchical
▪ Network
▪ Relational
▪ Entity relationship
▪ Object oriented
EVOLUTION OF DATA MODELS
EVOLUTION OF DATA MODELS
RELATIONAL MODEL
▪ The Relational Model represented a major breakthrough for both users and
designers.
▪ Its conceptual simplicity set the stage for a genuine database revolution.
▪ The Relational Model stores data in a matrix composed of intersecting rows
and columns referred to as a relation (tables). Each row in a relation is called
a tuple.
▪ The relational database is a collection of tables in which data are stored.
▪ Tables are related to each other through the sharing of a common attribute.
▪ A relational diagram is used to represent the relational database’s entities,
the attributes within those entities, and the relationships between those
entities.
RELATIONAL DIAGRAM
RELATIONAL DATABASE KEYS
Key Type Definition
Composite Two or more attributes that uniquely identify a row in a database table
key
Super key A set of attributes within a table that uniquely identifies each row
within a table.
Candidate A super key with no redundant attributes. Candidate keys are defined
key as the set of fields from which primary key can be selected.
Primary key A candidate key that is selected to uniquely identify each record (row)
in a relation (table). It is the main key of the table.
Secondary A candidate key which is not selected for primary key. Secondary keys
Key are used strictly for data retrieval purposes
Foreign Key An attribute or set of attributes within one relation (table) that
matches the candidate key of another relation (table)
RELATIONAL DATABASE KEYS
RELATIONAL DATABASE KEYS
▪ Composite Key: EMPLOYEE_ID, EMPLOYEE_NAME or SSN, EMPLOYEE_NAME
▪ Super key: EMPLOYEE_ID or EMP_PASSPORT_NUM or LICENCE_NUMBER or
SSNN or a combination of these fields with other fields e.g. SSN,
EMPLOYEE_NAME
▪ Candidate key: EMPLOYEE_ID or EMP_PASSPORT_NUM or
LICENCE_NUMBER or SSN
▪ Primary key: EMPLOYEE_ID
▪ Secondary key: EMP_PASSPORT_NUM or
LICENCE_NUMBER or SSNN
▪ Foreign Key: DEPARTMRNT_NUMBER
ENTITY RELATIONAL MODEL
▪ The Relational Model (ER) was a vast improvement over the hierarchical
and network models, it still lacked the features that would make it an effective
database design tool.
▪ The relational data model and ERM combined to provide the foundation for
tightly structured database design.
Heading
4
COMPONENTS OF RELATIONAL
DATABASE STRUCTURAL TERMINOLOGY
Relation
• a table with columns and rows
7
COMPONENTS OF RELATIONAL
DATABASE STRUCTURAL TERMINOLOGY
Exercise:
Identify:
a. Name of the relation.
b. Cardinality of the relation.
c. Degree of the relation.
d. Suitable domain for column Type.
e. Suitable domain for column Date of Birth.
8
PROPERTIES OF TABLES IN A
RELATIONAL DATABASE
Value Column
s are values are of
the same kind
atomi
c
The The
sequence of sequence of
rows is columns is
insignificant insignificant
Each Each
column
row is must
have a
uniqu unique 10
name
e
CHARACTERISTICS OF RELATION SCHEME
Relation scheme
Named relation defined by a set of attribute
and domain name pairs.
Characteristics:
a. Relation name
b. Attribute name
c. Domains
Syntax:
11
RelationName (attribute-1, attribute-2…
attribute-n)
CHARACTERISTICS OF RELATION SCHEME
Example:
Table name: Animal_Vaccination
12
RELATION INSTANCE
A tuple at a specifc moment of time
Eg: Student (StudentId, firstName, lastName, courseId)
The relation instance for Student:
(L0002345, Jim, Black, C002)
(L0001254, James, Harradine, A004)
The relation instance changed when the tuple is updated,
deleted or inserted
13
RELATION KEYS
1) Candidate key
- Any set of one or more columns whose combined values are
unique among all occurrences (i.e., tuples or rows).
No
- component of a candidate key is allowed to be null.
There
- can be any number of candidate keys in a table.
14
RELATION KEYS
2) Primary key (identifier)
- Any candidate key of that table which the database
designer arbitrarily designates as "primary".
- The primary key may be selected for convenience,
comprehension, performance, or any other reasons.
15
RELATION KEYS
16
RELATION KEYS
17
RELATION KEYS
Exercise:
Identify:
i. candidate key
ii. primary key
18
INTEGRITY RULES
Data integrity means that the data values in the
database are correct and consistent.
Integrity constraints provide a way of ensuring that changes
made to the database by authorized users do not result
in a loss of data consistency
19
INTEGRITY RULES
1) Entity Integrity
- states that “for every instance of an entity, the value of the
2) Referential Integrity
- states that “every foreign key value must match a primary
entities
20
INTEGRITY RULES
Exercise
:
Identify:
a. Suggest suitable name for the relation. Senior_Citizen, Member, Neighbour
b. Cardinality of the relation.
c. Degree of the relation.
d. Suitable domain for column Last Name.
e. Suitable domain for column City.
22
f. Suitable domain for column Age.
EXERCISE
Identify:
a. Suggest suitable name for the relation.
b. Cardinality of the relation.
c. Degree of the relation.
d. Suitable domain for column ID.
e. Suitable domain for column Class.
23
f. Suitable domain for column Mark.
Exercise
• Consider the business rule below:
• A company has several departments.
• Each department has a supervisor and at least one employee.
• Employees must be assigned to at least one department.
• Project will be given to the employee and it will be done in a group.
• At least one employee is assigned to one project or more.
• The important data fields are the names of the departments, projects,
supervisors and employees, as well as the supervisor and employee
number, department code and a unique project number
• Required:
• Identify all the entities
• List atleast 3 attributes for each entity
• List the relationships btween the entities identified
• Draw an ERD