UNIT-2: Entanty Instance
UNIT-2: Entanty Instance
UNIT-2: Entanty Instance
Entanty instance :
An entity type is a single occurrence of an entity type. An entity type is
described just once in a database, while many instances of that entity type
may be represented by data stored in the database.
For example , there is one employee entity type in most organisations, but
there may be hundreds of instances of this entity type stored in the database.
E-R Model:
Any entity-relationship diagram(ERD) shows the relationship of
entity sets stored in a database. An entity in this context is a
component of data. In other words, ERdiagrams describe the logical
structure of databases. At first glance, an entity-relationship
diagram looks very much like a flow chart. It contains the
specialised symbols, and the meanings of those symbols, that
make it unique.
1. Components of E-R MODEL
The three main components of the ER MODEl are:
1. Entities
2. Attributes
3. Relationships
1.Entity
In ERM terms, an entity is a thing within the organisation that we
want to keep information about, such as a customer employee or
course. They are typically nouns. In other words, an entity in an
ERM actually refers to a table, and rows within the table are
referred to as entity occurrences.
Entities are represented by rectangles containing the name of the
entity. Entity names must be singular and in capital letters. There
are three types of entities discussed below;
● Strong entities: They exist independently from other entity
type. They always have one or more attributes that uniquely
distinguish each occurrence of the entity.
● Weak entities: They depend on same other entity. They do not
have unique attributes and have no meaning in the diagram
without depending on another entity . This other entity is
known as the owner.
● Associative entities: these are entities that associate the
instances of one or more entity types.
2. Attribute
An attribute is a property or descriptor of an entity.
Type of attributes
Depending on the nature of the attribute, they are classified
into five types.
● Required and optional attributes
A required attribute is an attribute that must have a value in it, while
an optional attribute may not have a value in it and can be left
blank.
Example: in the entity employee, E_ID, Name,Age and salary
would be required attributes as they uniquely define that table and
we assume all employees have E_ID, Name, Age and salary.
● Key and non-key attribute
In every entity an attribute or group of attributes uniquely identifies
that entity.
Example: above in the table employee, there is only one unique
identities, E_ID, which is the primary key of the table. The rest of
the attributes are descriptions.
● Single and composite attributes
The composite attribute is an attribute that can be subdivided into
other single attributes with meanings of their own.
Example: in entity employee, the attribute name can be divided into
first name, can be divided into first name, last name, and middle
name. The rest of attributes are called single attributes since they
connote be subdivided into parts.
● single -valued and multi-valued attributes
The single-value attribute can only have one value, while the
multi-valued attributes usually can store multiple data in them.
For example, in the entity employee, Phno could be considered a
muti-value attribute since an employee could have multiple phone
numbers.
● Derived attributes
The value of derived attribute is calculated from the value of other
attribute.
For example, in employee table, age would be considered as a
derived attribute since it could be calculated using the employee’
date of birth.
3. Relationship
Relationship describe how entities are associated with each other.
The two entities would be the employee and the department and
the act of working would be the relationship among the entities.
2.Degree of relationship
The following are the different types of relationships depending on
their degree:
1. Unary relationship
2. Binary relationship
3. Ternary relationship
1. Unary relationship
These are relationships which involve a single entity. These
relationships are also called recursive relationships
2. Binary relationship
Binary relationship is formed when two entities participate in a
relationship
3. Ternary relationship
A ternary relationship is formed when three entities participate in a
relationship
3.Cardinality
Four types of cardinalities are generally discussed.
1. One to one
2. One to many
3. Many to one
4. Many to many
1. One to one :
In this type of relationship, one instance is one entity set is related
to only one instance in other entity set. The relation is denoted as
1:1 or 1-1.
2. One to many:
Here, one instance in one entity set is related to more than one
instance in other entity set. The notation is 1:* or 1-*. In the given
example, one customer can place many orders and many orders
can be placed by one customer.
3. Many to one:
Here, many instances in one entity set are related to one instance
in other entity set. The notation is *:1 or *-1. In the given example,
many employees may belong to one department and one particular
employee can belong to one department only.
4. Many to many :
In this type of relationship, many instances in one entity set are
related to many instances is other entity set. The notation is *:* or
*-*. In the given example, many students can enroll in many
courses.
Specialization –
1.In specialization, an entity is divided into sub-entities based on
their characteristics.
2.It is a top-down approach where higher level entity is specialized
into two or more lower level entities.
Let’s assume that there is a patient who has visited a doctor in the
hospital to seek treatment for a certain type of illness. The following
diagram shows the process flow for aggregation in the hospital.
Image Source: EDUCBA
The database stores data regarding this diagnosis and any other
patient data. Filing is required to make it easier for the doctor to
retrieve the patient’s information in the future.
In this example, the patient cannot work on his own. He has to form
a relationship with the doctor to get a diagnosis. The doctor also
cannot perform a diagnosis without the patient. In the future, the
doctor will need data about the patient’s history, that will require him
to collect it from a filing system.
The last entity (patient’s history) ensures that the entire system is
functional. Getting the patient’s history cannot be done without a
diagnosis from the doctor and a filing system.
ER Design Issues
In the previous sections of the data modeling, we learned
to design an ER diagram. We also discussed different ways
of defining entity sets and relationships among them. We
also understood the various designing shapes that
represent a relationship, an entity, and its attributes.
However, users often mislead the concept of the elements
and the design process of the ER diagram. Thus, it leads to
a complex structure of the ER diagram and certain issues
that does not meet the characteristics of the real-world
enterprise model.
1 X Hyderabad
2 Y Chennai
3 Z Bangalore
4 P null
If we try to get number of employees using address column..
Count(address)
null value.