You are on page 1of 7

2 Lesson 2: ER-Modeling

Relational Model (RM) represents the database as a collection of relations. A relation is nothing but
a table of values. Every row in the table represents a collection of related data values. These rows in
the table denote a real-world entity or relationship.

Entity Relationship Model (ER Modeling) is a graphical approach to database design. It is a high-level
data model that defines data elements and their relationship for a specified software system. An ER
model is used to represent real-world objects.

ER Modeling helps you to analyze data requirements systematically to produce a well-designed


database. Thus, it is always considered a best practice to complete ER modeling before implementing
a database.

Relational Model Concepts

An entity is object, or component of data, that is easily identifiable. It is object in real world that is
distinguishable from the surrounding environment For example, in a university database,
students, lecturers, programs, and courses offered can be considered as entities. All these
entities have some attributes that describe them.

Attribute: Each column in a table is an attibute. Attributes are the properties which define a relation.
e.g. StudentId, StudentName, email etc. define the relation students

Reading Assignment: Read about the different types of attributes and suggest valid examples

Tables – In the Relational model the, relations are saved in the table format. It is stored along with its
entities. A table has two properties rows and columns. Rows represent records and columns
represent attributes.

Tuple – It is nothing but a single row of a table, which contains a single record.

Relation Schema: A relation schema represents the name of the relation with its attributes.

Degree: The total number of attributes which in the relation is called the degree of the relation.

Cardinality: Total number of rows present in the table.

Column: The column represents the set of values for a specific attribute.

Relation instance – Relation instance is a finite set of tuples in the RDBMS system. Relation instances
never have duplicate tuples.

Relation key - Every row has one, two or multiple attributes, which is called relation key.

Reading Assignment: Distinguish between a superkey, candidate key, and a primary key

Attribute domain – Every attribute has some pre-defined value and scope which is known as attribute
domain

Relationship - is used to describe the association between entities. The number of participating
entities in a relationship defines the degree of the relationship.

Reading Assignment: Read about 1:1, 1:m, m:1, and m:m relationships

1
ER Modeling Symbols and Notations

ER Modelling contains three basic symbols which are rectangle, oval and diamond to represent
relationships between elements, entities and attributes. The following are the main components and its
symbols in ER Diagrams:

i. Rectangles: This Entity Relationship Diagram symbol represents entity types


ii. Ellipses: Symbol represent attributes
iii. Diamonds: This symbol represents relationship types
iv. Lines: It links attributes to entity types and entity types with other relationship types
v. Primary key: attributes are underlined
vi. Double Ellipses: Represent multi-valued attributes

Reading Assignment: Read about weak relationships, weak entities, and Multivalued attributes

Components of the ER Diagram

This model is based on three basic concepts:

 Entities
 Attributes
 Relationships

Advantages of using Relational Model


i. Simplicity: A Relational data model in DBMS is simpler than the hierarchical and
network model.
ii. Structural Independence: The relational database is only concerned with data and
not with a structure. This can improve the performance of the model.
iii. Easy to use: The Relational model in DBMS is easy as tables consisting of rows and
columns are quite natural and simple to understand
iv. Query capability: It makes possible for a high-level query language like SQL to
avoid complex database navigation.
v. Data independence: The Structure of Relational database can be changed without
having to change any application.
vi. Scalable: Regarding a number of records, or rows, and the number of fields, a database
should be enlarged to enhance its usability.

2
Disadvantages of using Relational Model
i. Few relational databases have limits on field lengths which can't be exceeded.
ii. Relational databases can sometimes become complex as the amount of data grows,
and the relations between pieces of data become more complicated.
iii. Complex relational database systems may lead to isolated databases where the
information cannot be shared from one system to another.

Best Practices for creating a Relational Model

 Data need to be represented as a collection of relations


 Each relation should be depicted clearly in the table
 Rows should contain data about instances of an entity
 Columns must contain data about attributes of the entity
 Cells of the table should hold a single value
 Each column should be given a unique name
 No two rows can be identical
 The values of an attribute should be from the same domain
Example 1: Programs and Students
Consider the following proposition and develop an appropriate ER Model.

“Programs have Students”

To develop an ER model for the above requirements, the following steps are taken.
1. Identify all the entities from the given requirement
2. Identify the relationship between the entities
3. Identify the cardinality of the relationships
4. Identify the attributes of each entity
5. Create a sketch of the model using a pen and paper

Assignment 1:
Consider a basic requirement using the following sentence.

“In a hospital there are doctors who treat patients.

The patients are prescribed one or more drugs”

Follow the same steps above / as demonstrated during the Lab session to draw an ER Model.

Assignment 2: MyLibSeat
MyLibSeat is a small application that utilizes database to enable the students of XYZ college to
reserve a library seat, for a session lasting a couple of hours. The two major entities in this case
are students—students who reserve library seats; and library seats —seats in the college library
inventory. In this problem we need to know what seats are reserved by which students on a given

3
day, or better still, a given hour. Thus, the verb “reserves” would obviously represent an important
relationship here.

The attributes of the student entity are:

regno each student is assigned a unique ID


name the student name
phone the phone contact for a student
email the email contact for a student
credit the max number of hours that a student can reserve seats in a day
Attributes of the seat entity

seatno each seat is assigned a unique ID (painted at the back of the seat)
seat_type The type of the seat (also painted on the bow)
seat_color The color of the seat
Note:

A student can make many reservations, but each reservation involves only a single student.
Similarly, a seat can be allocated to many reservations, but only one seat is allocated to each
particular reservation.

Required:

Draw an ER-Model that captures the above information.

4
3 Lesson 3: Relational Integrity Constraints
Relational integrity constraints in DBMS are referred to conditions which must be present for a valid
relation. Constraints on the Relational DBMS are divided into three main categories:

 Domain Constraints
 Key Constraints
 Referential Integrity Constraints

Domain Constraints

Domain constraints can be violated if an attribute value is not appearing in the corresponding domain
or it is not of the appropriate data type. Each table has certain set of columns. Each column only allows
entry of same type of data, based on its specified data type during table definition. The column does
not accept values of any other data type.

Thus domain constraints can be defines as follows;

Domain Constraint = data type + Constraints (NOT NULL / UNIQUE / PRIMARY KEY /
FOREIGN KEY / CHECK / DEFAULT)
Key Constraints

An attribute that can uniquely identify a tuple in a relation is called the key of the table. The value of
the attribute for different tuples in the relation has to be unique.

Example: In the given table, StudentID is a key attribute of students table. It is most likely
to have a single key for one student, StudentID =1 is only for the student name " Alex
Jones".

StudentID StudentName phone email


1 Alex Jones 0721 001001 ajones@xyz.ac.ke
2 Maria Joseph 0721 052073 mjoseph@xyz.ac.ke
3 Cathy Peters 0721 501789 cpeter@xyz.ac.ke
Referential Integrity Constraints
Referential Integrity constraints in DBMS are based on the concept of Foreign Keys. A foreign
key is an important attribute of a relation which should be referred to in other relationships.
Referential integrity constraint state happens where relation refers to a key attribute of a
different or same relation. However, that key element must exist in the table.

Example: In the example below, we have 2 relations, students and programs. The tuple
for ProgramID =11 in the programs relation is referenced twice in the relation students.

StudentID StudentName phone email FK_ProgramID


1 Alex Jones 0721 001001 ajones@xyz.ac.ke 11
2 Maria Joseph 0721 052073 mjoseph@xyz.ac.ke 11
3 Cathy Peters 0721 501789 cpeter@xyz.ac.ke 13
4 Timothy J 15

5
ProgramID Program DepartmentID
11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 3
Operations in Relational Model

The basic update operations performed on relational database model are: Insert, update, delete
and select.

 Insert is used to insert data into the relation


 Update allows you to change the values of some attributes in existing tuples.
 Delete is used to delete tuples from the table.
 Select allows you to choose a specific range of data.

Whenever one of these operations is performed, integrity constraints specified on the


relational database schema must never be violated, else the operation is aborted.
Insert Operation
The insert operation gives values of the attribute for a new tuple which should be inserted into
a relation.

ProgramID Program DepartmentID


11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 3
14 BSc. Economics 7
Update Operation
Example: In programs table, the tuple with program as 'BSc. Data Science’ is edited
with the attribute DepartmentID being updated from 3 to 1.

ProgramID Program DepartmentID


11 BSc. Computer Science 1
12 BSc. Statistics 2
13 BSc. Data Science 1
14 BSc. Economics 7
Delete Operation
To specify deletion, a condition on the attributes of the relation selects the tuple to be deleted.

Example: From the programs relation, delete the tuple(s) with program name as “BSc. Data
Science”.

6
ProgramID Program DepartmentID
11 BSc. Computer Science 1
12 BSc. Statistics 2
14 BSc. Economics 7
The Delete operation could violate referential integrity if the tuple which is deleted is
referenced by foreign keys from other tuples in the same database.
Select Operation
Example: From the programs relation, select the tuples satisfying the condition Program=
‘BSc. Statistics’

ProgramID Program DepartmentID


12 BSc. Statistics 2

Lab: ER Modelling Case Study

Consider the following data requirements that were provided by a college to aid in the development of
their ERP system.

XYZ college is a higher learning institution that offers training in various disciplines such as
Pharmacy, Engineering, Music, among others. The college is structured into various departments
where each department runs one or more programs. For Example, the programs Diploma in
Pharmacy, and Certificate in Pharmacy are housed in the Department of Pharmacy. Each program
is composed of a finite number of course units. Course units are identified using unit codes, unit
titles, credit hours, and unit type. Some units are shared across several programs in the college.
For instance, course units of the type “common units” are shared by all programs in the college;
“departmental units” are shared by all programs in a department, while “core units” are not shared
at all.

Students in the college are identified using admission number, names, email, phone, etc. A student
can be enrolled to only one program. The college maintains a register of Trainers using their
employment number, names, email, phone, ID number etc. In addition, each trainer belongs to one
of the various departments of the college.

The college adopts learning terms, which runs concurrently for all programs. Each term has a
name, start date, end date, exam date as its attributes e.g. the term “JAN_MAR_2020” begins on
01/01/2020, and ends on 31/03/2020, and exams begin on 23/03/2020.

At the onset of each term, a sub set course units are offered by each department. Students can only
register for one or more course units that have been put on offer. A trainer is assigned to teach one
or more course units that are on offer. Thus, a separate entity “courses on offer” is maintained
with the following attributes: course unit, term, trainer, venue, date, and time.

Required:

i. Identify and list all entities that can be derived from these requirements.
ii. Identify and list the relationships between the entities in (i) above, where applicable.

You might also like