Lesson 8 Database Management System M5
Lesson 8 Database Management System M5
Tuguegarao City
Prepared by:
Ceferino Llamelo
Instructor
Reviewed by:
Recommended by:
Approved by:
For this week of this grading period, the following shall be your guide for the different lessons and tasks that
you need to accomplish. Be patient, read it carefully before proceeding to the tasks expected of you.
GOOD LUCK! Have Fun
Learning Outcomes: At the end of this module, you are expected to:
LEARNING CONTENT
Lesson Proper:
One-to-many − One entity from entity set A can be associated with more than one entities of entity set
B however an entity from entity set B, can be associated with at most one entity.
Many-to-many − One entity from A can be associated with more than one entity from B and vice
versa.
ER Diagram Representation
Let us now learn how the ER Model is represented by means of an ER diagram. Any object, for example,
entities, attributes of an entity, relationship sets, and attributes of relationship sets, can be represented with
the help of an ER diagram.
Entity
Entities are represented by means of rectangles. Rectangles are named with the entity set they represent.
Attributes
Attributes are the properties of entities. Attributes are represented by means of ellipses. Every ellipse
represents one attribute and is directly connected to its entity (rectangle).
If the attributes are composite, they are further divided in a tree like structure. Every node is then connected to
its attribute. That is, composite attributes are represented by ellipses that are connected with an ellipse.
Relationship
Relationships are represented by diamond-shaped box. Name of the relationship is written inside the
diamond-box. All the entities (rectangles) participating in a relationship, are connected to it by a line.
Binary Relationship and Cardinality
A relationship where two entities are participating is called a binary relationship. Cardinality is the number of
instance of an entity from a relation that can be associated with the relation.
One-to-one − When only one instance of an entity is associated with the relationship, it is marked as
'1:1'. The following image reflects that only one instance of each entity should be associated with the
relationship. It depicts one-to-one relationship.
One-to-many − When more than one instance of an entity is associated with a relationship, it is
marked as '1:N'. The following image reflects that only one instance of entity on the left and more than
one instance of an entity on the right can be associated with the relationship. It depicts one-to-many
relationship.
Many-to-one − When more than one instance of entity is associated with the relationship, it is marked
as 'N:1'. The following image reflects that more than one instance of an entity on the left and only one
instance of an entity on the right can be associated with the relationship. It depicts many-to-one
relationship.
Participation Constraints
Total Participation − Each entity is involved in the relationship. Total participation is represented by
double lines.
Partial participation − Not all entities are involved in the relationship. Partial participation is
represented by single lines.
Generalization Aggregation
The ER Model has the power of expressing database entities in a conceptual hierarchical manner. As the
hierarchy goes up, it generalizes the view of entities, and as we go deep in the hierarchy, it gives us the detail
of every entity included.
Going up in this structure is called generalization, where entities are clubbed together to represent a more
generalized view. For example, a particular student named Mira can be generalized along with all the
students. The entity shall be a student, and further, the student is a person. The reverse is
called specialization where a person is a student, and that student is Mira.
Generalization
As mentioned above, the process of generalizing entities, where the generalized entities contain the
properties of all the generalized entities, is called generalization. In generalization, a number of entities are
brought together into one generalized entity based on their similar characteristics. For example, pigeon,
house sparrow, crow and dove can all be generalized as Birds.
Specialization
Specialization is the opposite of generalization. In specialization, a group of entities is divided into sub-groups
based on their characteristics. Take a group ‘Person’ for example. A person has name, date of birth, gender,
etc. These properties are common in all persons, human beings. But in a company, persons can be identified
as employee, employer, customer, or vendor, based on what role they play in the company.
Similarly, in a school database, persons can be specialized as teacher, student, or a staff, based on what role
they play in school as entities.
Inheritance
For example, the attributes of a Person class such as name, age, and gender can be inherited by lower-level
entities such as Student or Teacher.
Relation Data Model
Relational data model is the primary data model, which is used widely around the world for data storage and
processing. This model is simple and it has all the properties and capabilities required to process data with
storage efficiency.
Concepts
Tables − In relational data model, relations are saved in the format of Tables. This format stores the relation
among entities. A table has rows and columns, where rows represents records and columns represent the
attributes.
Tuple − A single row of a table, which contains a single record for that relation is called a tuple.
Relation instance − A finite set of tuples in the relational database system represents relation instance.
Relation instances do not have duplicate tuples.
Relation schema − A relation schema describes the relation name (table name), attributes, and their names.
Relation key − Each row has one or more attributes, known as relation key, which can identify the row in the
relation (table) uniquely.
Attribute domain − Every attribute has some pre-defined value scope, known as attribute domain.
Constraints
Every relation has some conditions that must hold for it to be a valid relation. These conditions are
called Relational Integrity Constraints. There are three main integrity constraints −
Key constraints
Domain constraints
Referential integrity constraints
Key Constraints
There must be at least one minimal subset of attributes in the relation, which can identify a tuple uniquely.
This minimal subset of attributes is called key for that relation. If there are more than one such minimal
subsets, these are called candidate keys.
Key constraints force that −
in a relation with a key attribute, no two tuples can have identical values for key attributes.
a key attribute can not have NULL values.
Key constraints are also referred to as Entity Constraints.
Domain Constraints
Mapping Process
Create table for a relationship.
Add the primary keys of all participating Entities as fields of table with their respective data types.
If relationship has any attribute, add each attribute as field of table.
Declare a primary key composing all the primary keys of participating entities.
Declare all foreign key constraints.
Mapping Weak Entity Sets
A weak entity set is one which does not have any primary key associated with it.
Mapping Process
Create tables for all higher-level entities.
Create tables for lower-level entities.
Add primary keys of higher-level entities in the table of lower-level entities.
In lower-level tables, add all other attributes of lower-level entities.
Declare primary key of higher-level table and the primary key for lower-level table.
Declare foreign key constraints.
*** END of LESSON 7***
Multiple choice: Write your answer on the space provided. Select the best answer that suits the question or
statement
APPLICATION
TITLE:
Entity Relationship diagram
OBJECTIVES:
To draw a sample ENTITY RELATIONSHIP DIAGRAM diagram for real project or system.
ALLOTED TIME: 60 minutes
INSTRUCTION:
1. Create the SRS of the problem statement created in activity 1
THEORY
Entity Relationship Diagrams are a major data modelling tool and will help organize the data in your project
into entities and define the relationships between the entities. This process has proved to enable the analyst
to produce a good database structure so that the data can be stored and retrieved in a most efficient manner.
Entity
A data entity is anything real or abstract about which we want to store data. Entity types fall into five classes:
roles, events, locations, tangible things or concepts. E.g. employee, payment, campus, book. Specific
examples of an entity are called instances. E.g. the employee John Jones, Mary Smith's payment, etc.
Relationship
A data relationship is a natural association that exists between one or more entities. E.g. Employees process
payments. Cardinality defines the number of occurrences of one entity for a single occurrence of the related
entity. E.g. an employee may process many payments but might not process any payments depending on the
nature of her job.
Attribute
A data attribute is a characteristic common to all or most instances of a particular entity. Synonyms include
property, data element, field. E.g. Name, address, Employee Number, pay rate are all attributes of the entity
employee. An attribute or combination of attributes that uniquely identifies one and only one instance of an
entity is called a primary key or identifier. E.g.
Employee Number is a primary key for Employee.
AN ENTITY RELATIONSHIP DIAGRAM METHODOLOGY: (One way of doing it)
Identify the roles, events, locations, tangible things or concepts about
1. Identify Entities which the end-users want to store data.
Find the natural associations between pairs of entities using a
2. Find Relationships relationship
matrix.
Put entities in rectangles and relationships on line segments connecting the
3. Draw Rough ERD entities.
Determine the number of occurrences of one entity for a single
4. Fill in Cardinality occurrence
of the related entity.
Identify the data attribute(s) that uniquely identify one and only one
5. Define Primary Keys
COME 1044 – Software Design | 12
occurrence of each entity.
Eliminate Many-to-Many relationships and include primary and foreign
6. Draw Key-Based ERD keys in each entity.
Name the information details (fields) which are essential to the system
7. Identify Attributes under development.
8. Map Attributes For each attribute, match it with exactly one entity that it
describes.
9. Draw fully attributed ERD Adjust the ERD from step 6 to account for entities or relationships
discovered in step 8.
Does the final Entity Relationship Diagram accurately depict the system
10. Check Results data?
A SIMPLE EXAMPLE
A company has several departments. Each department has a supervisor and at least one employee.
Employees must be assigned to at least one, but possibly more departments. At least one employee is
assigned to a project, but an employee may be on vacation and not assigned to any projects. The important
data fields are the names of the departments, projects, supervisors and employees, as well as the supervisor
and employee number and a unique project number.
1. Identify Entities
The entities in this system are Department, Employee, Supervisor and Project. One is tempted to make
Company an entity, but it is a false entity because it has only one instance in this problem. True entities must
have more than one instance.
2. Find Relationships
We construct the following Entity Relationship Matrix:
Department Employee Supervisor Project
Department is assigned run by
Employee belongs to works on
Supervisor runs
Project uses
3. Draw Rough ERD
We connect the entities whenever a relationship is shown in the entity Relationship Matrix.
REFERENCES
Internet Sites