Second Lecture
Second Lecture
Database Models
In this lesson we explain the following things:
When the computer appeared at first time, the first thing human thought was to find ways to store
data preserve and retrieve it if needed. At the beginning they used file system to achieve this
task. Later they built data models for accomplishing these operations. The main object for these
database models was to represent the data of the real world in simple and agreed method.
The notion of a ”data model” is one of the most fundamental in the study of database systems. In
this brief summary of the concept, we define some basic terminology and mention the most
important data models. A data model is a notation for describing data or information. The
description generally consists of three parts:
1. Structure of the data. The data structures used to implement data in the computer are
sometimes referred to as a physical data model. In the database world, data models are at a
somewhat higher level than data structures, and are sometimes referred to as a conceptual
model to emphasize the difference in level.
2. Operations on the data. In database data models, there is usually a limited set of operations
that can be performed. We are generally allowed to perform a limited set of queries
(operations that retrieve information) and modifications (operations that change the
database). By limiting operations, it is possible for programmers to describe database
operations at a very high level, yet have the database management system implement the
operations efficiently.
ADVANCED DATABASE QASIM RADAM
3. Constraints on the data. Database data models usually have a way to describe limitations on
what the data can be. These constraints can range from the simple (e.g., ”a day of the week is
an integer between 1 and 7” or ”a movie has at most one title”) to some very complex forms
of limitations.
Many types of database models were appeared in the last duration which as follows:
1. Hierarchical database Model is a data model in which data is arranged in the form of a
tree appeared in the early 1960s. Figure in the below represents it.
2. Network database Model is a data model in which data is arranged in the form of a
network of records appeared in the early 1960s figure in the below represents it. In this
model, each record can be represented as a master record and its sub-records that sub
divided from it. Figure in the below represents it.
ADVANCED DATABASE QASIM RADAM
Figur
e shows Network database Model
3. Relational database Model is the model that was designed by the scientist Codd in 1970. Today can
be running the software that depend on the relational database in the all devices such computer,
mobile and others. On the other hand, Relational database Model is considered simpler and also less
complicated compare with the others models. The database management system that used to manage
database of this model called Relational DataBase Management System (DBMS). In our study we
will focus on the Relational database Model. The next figure represents this model.
ADVANCED DATABASE QASIM RADAM
Entity-relationship model
Entity-relationship model depends on three main components, Entities, Attributes, and Relations.
ADVANCED DATABASE QASIM RADAM
1. Entity is an entity or thing that exists in the real world and is the focus of attention of the
system and can be distinguished from other entities. Also, it is the entity or the thing that we
collect the data about it. For example, in the school system we will find number of entities
such as student, teacher, subject, class.
The supermarket system also represents another example that includes number of entities such as
customer, product and invoice.
ADVANCED DATABASE QASIM RADAM
2. Attributes are represented the characteristics of the entity that distinguishes it from another
entity, they are the data that should be stored about this entity. These attributes may be share
between two entities or more or different. The following example explains that.
In the school system, we have number of entities such as student, teacher, subject, class, etc.
Student Entity:
Medicine Entity:
ADVANCED DATABASE QASIM RADAM
What is ER Diagrams?
Entity Relationship Diagram (ERD) displays the relationships of entity set stored in a database.
In other words, we can say that ER diagrams help you to explain the logical structure of
databases. At first look, an ER diagram looks very similar to the flowchart. However, ER
Diagram includes many specialized symbols, and its meanings make this model unique.
Entities
Attributes
Relationships
ADVANCED DATABASE QASIM RADAM
Example
For example, in a University database, we might have entities for Students, Courses, and
Lecturers. Students’ entity can have attributes like Rollno, Name, and Dept ID. They might have
relationships with Courses and Lecturers.
What is entity?
A real-world thing is either living or non-living that is easily recognizable and nonrecognizable.
It is anything in the enterprise that is to be represented in our database. It may be a physical thing
or simply a fact about the enterprise or an event that happens in the real world.
An entity can be place, person, object, event or a concept, which stores data in the database. The
characteristics of entities are must have an attribute, and a unique key. Every entity is made up of
some 'attributes' which represent that entity.
Examples of entities:
Entity set:
Student
An entity set is a group of similar kind of entities. It may contain entities with attribute sharing
similar values. Entities are represented by their properties, which also called attributes. All
attributes have their separate values. For example, a student entity may have a name, age, class,
as attributes.
Relationship
Relationship is nothing but an association among two or more entities. E.g., Tom works in the
Chemistry department.
Entities take part in relationships. We can often identify relationships with verbs or verb phrases.
For example:
Weak Entities
A weak entity is a type of entity which doesn't have its key attribute. It can be identified uniquely
by considering the primary key of another entity. For that, weak entity sets need to have
participation.
Let's learn more about a weak entity by comparing it with a Strong Entity.
Strong entity set always has a primary key. It does not have enough attributes to build a
primary key.
It contains a Primary key represented by the It contains a Partial Key which is represented
underline symbol. by a dashed underline symbol.
The member of a strong entity set is called as The member of a weak entity set called as a
dominant entity set. subordinate entity set.
Primary Key is one of its attributes which In a weak entity set, it is a combination of
helps to identify its member. primary key and partial key of the strong
entity set.
In the ER diagram the relationship between The relationship between one strong and a
two strong entity set shown by using a weak entity set shown by using the double
diamond symbol. diamond symbol.
ADVANCED DATABASE QASIM RADAM
The connecting line of the strong entity set The line connecting the weak entity set for
with the relationship is single. identifying relationship is double.
Attributes
For example, a lecture might have attributes: time, date, duration, place, etc.
Cardinality
Defines the numerical attributes of the relationship between two entities or entity sets.
One-to-One Relationships
One-to-Many Relationships
May to One Relationships
Many-to-Many Relationships
1. One-to-one:
One entity from entity set X can be associated with at most one entity of entity set Y and vice
versa.
Example: One student can register for numerous courses. However, all those courses have a
single line back to that one student.
ADVANCED DATABASE QASIM RADAM
One-to-many:
One entity from entity set X can be associated with multiple entities of entity set Y, but an entity
from entity set Y can be associated with at least one entity.
3. Many to One
More than one entity from entity set X can be associated with at most one entity of entity set Y.
However, an entity from entity set Y may or may not be associated with more than one entity
from entity set X.
4. Many to Many:
One entity from X can be associated with more than one entity from Y and vice versa.
For example, Students as a group are associated with multiple faculty members, and faculty
members can be associated with multiple students.
ER- Diagram is a visual representation of data that describe how data is related to each other.
In a university, a Student enrolls in Courses. A student must be assigned to at least one or more
Courses. Each course is taught by a single Professor. To maintain instruction quality, a Professor
can deliver only one course
Student
Course
Professor
You need to study the files, forms, reports, data currently maintained by the organization to
identify attributes. You can also conduct interviews with various stakeholders to identify entities.
Initially, it's important to identify the attributes without mapping them to a particular entity.
Once, you have a list of Attributes, you need to map them to the identified entities. Ensure an
attribute is to be paired with exactly one entity. If you think an attribute should belong to more
than one entity, use a modifier to make it unique.
Once the mapping is done, identify the primary Keys. If a unique key is not readily available,
create one.
For Course Entity, attributes could be Duration, Credits, Assignments, etc. For the sake of ease
we have considered just one attribute.
Foreign Key
Conceptual ERD models the business objects that should exist in a system and the
relationships between them. A conceptual model is developed to present an overall picture of
the system by recognizing the business objects involved. It defines what entities exist, NOT
ADVANCED DATABASE QASIM RADAM
which tables. For example, 'many to many' tables may exist in a logical or physical data model
but they are just shown as a relationship with no cardinality under the conceptual data model.
NOTE: Conceptual ERD supports the use of generalization in modeling the 'a kind of'
relationship between two entities, for instance, Triangle, is a kind of Shape. The usage is like
generalization in UML. Notice that only conceptual ERD supports generalization.
Summary