0% found this document useful (0 votes)
94 views16 pages

DBMS 2 Unit

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views16 pages

DBMS 2 Unit

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

DBMS Shree Medha Degree College, Ballari

Unit - 02
E-R MODEL
Entity-Relationship Modeling
➢ Entity-Relationship model introduced by peter chinn in 1976.
➢ E-R model is a visual representation of data that describes how data is related to
each other(or)the E-R model defines the conceptual(logical) view of a database.
➢ ER model is a Graphical Representation of Entities, Attributes and
Relationships.
➢ ER models are represented in an Entity-Relational Diagram.
➢ The E-R model is based on the following components.

1. Entity:
➢ It is a “thing” or “object” in the real world. Which consists of either place, person,
animal, and so on.
➢ An Entity is represented in the E-R diagram by a Rectangle.
2. Attributes:
➢ It is nothing but characteristics or properties of an Entity.
➢ An attribute is represented by an ellipse. Each entity is described by a set of
attributes.
3. Relationship:
➢ Relationship describe association among data.
➢ Relationship is represented by a diamond.
Advantages:
➢ Visual Representation.
➢ Conceptual simplicity.
➢ Integrated with the relational data model.
Disadvantages:
➢ United relationship representation.
➢ It doesn’t support DML.
Example of E-R:

Name cid CName


Rno

STUDENT COURSE

Dept. of Computer Science 1 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari

E-R Diagram for Library Management


System

Dept. of Computer Science 2 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari

ER diagram for university management system

Dept. of Computer Science 3 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari

Types of Entity:
Entity: It is a collection of entities which share common properties (or)characteristics.

EMPID
EMPLOYEE

NAME

PHONE
AGE DOB

Types of Entities:
1. Strong Entity.
2. Week Entity.

1. Strong Entity:
➢ Strong entity is an entity which does not depends on other entity.
➢ It is an entity that meets two characteristics.
• It should not be existence dependent.

Dept. of Computer Science 4 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
• The primary key must not be derived.

Roll name sex


age
no

student

2. Weak entity:
➢ Weak Entity is an Entity which depends on other entity.
➢ It is an entity that meets two characteristics.
• it is existence dependent on a related entity.
• its primary key is totally or partially derived from the related entities primary
key.

Ename Age Type of


SS Cname
Age Insurance
N

Employee Belongs CHILD


to
toaeq

t
Example of Entity: consider the relationship between STUDENT and CERTIFICATE.
to

STUDENT CERTIFICATE

Entity Sets: The collection of all entities of a particular entity type in the database at
any point of time is known as entity set.
Ex: Employee refers to both type of entities.

Types of Attributes:
➢ An attribute is a characteristics or properties of an entity. Represented with
ellipse.
Ex: student→Rno, Sname, Mobileno, Address…. etc.
1. Required Attributes: It is an attribute that must have a value.
Ex: Name→Name attribute is a Required Attribute which have a value.

Dept. of Computer Science 5 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
2. Optional Attribute: It is an attribute that cannot that may(or)may not have a
value (it can be Null sometimes).
Ex: E-mail.
3. Simple Or Atomic Attribute: - It is an attribute that cannot be broken down into
smaller components.
Ex: Age.
4. Composite Attribute: It is an attribute that can be broken down into two (or)more
parts.
Ex: Name→Fname, Lname
5. Single value Attribute: It is an attribute that takes only one value.
Ex: Rno.
6. Multi value Attribute: It is an attribute that takes one or more values.
Ex: Lang-known.
7. Identifier Attribute: It is an attribute used to identify a row unique.
Ex: Rno
8. Composite Identifier Attribute: Sometimes primary key is composed of more
than one attribute such set of attributes is known as composite identifier.
Ex: Rno & Group-id.
9. Stored Attribute: It is an attribute stored in a database to supply values for a
derived attribute.it is used to compute the values of a derived attribute.
Ex: Subject marks→C-Lang, Acc…
10. Derived attribute: it is an attribute whose values can be calculated from
related attribute values.
Ex: Total, Avg, Net pay…. etc.

Key Attributes of An Entity Type


➢ A key attribute is a minimal set of attributes of an entity Set, which uniquely
identifies an entity in an entity set. A key may be a single attribute or may be more
than one attribute.
➢ An entity type usually has an attribute whose values are distinct for each
individual entity
➢ Such an attribute is called a key attribute, whose values can be used to identify
each entity.

Dept. of Computer Science 6 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
Example 1: For the company entity, name can be the key attribute because no the
companies can have the same name.
Example 2: For the student entity. Regno can be the key attribute
Example 3: For a person entity, social security number can be the key attribute.
Example 4: For an employee, empid can be the key attribute.
Sometimes key may be formed by the combination of several attributes- a
composite attribute. This means that the combination of the attribute values must be
distinct for each individual entity.
Sometimes each entity type can have more than one key attribute.
Example 5: The registration number is a composite attribute with two simple attributes,
state number and registration number, though neither of them is a key on its own.
Types of keys:
A key is an attribute or set of attributes that uniquely identifies any tuples from the
table.
There are six types of keys:
1. Super key
2. Candidate key
3. Primary key
4. Alternate key
5. Composite/Compound key
6. Foreign Key

1) Super key:

• It is a combination of all possible attributes that can uniquely identify tuple in


the given table.

• Super key is a super set of candidate key.


Eg:
Rno Name Email Aadhar Cid
1 Robo Robo@ 999542 10
2 Chitti Chitti@ 967823 30
3 Robo Robo@ 987901 10

Dept. of Computer Science 7 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
Super keys:

• Rno

• Email

• Aadhar no
• Rno + Aadhar no

• Rno + Name + Email id


2) Candidate key:

• It is an attribute which can uniquely identify a row.


• A candidate is a minimal super key.

• A candidate key has no redundant attribute.


Eg:

• Aadhar no
• Email id

• Rno
3) Primary key:

• A primary key is a column which can uniquely identify each row in a table.

• A primary key must contain unique values and cannot contain null values.
• A table can have only one primary key.
Eg: create table std(rno number(3) primary key,Name varchar(15), marks number(3));
Std
Rno Name Marks
1 Robo 700
2 Chitti 690
3 Robo 690
4) Alternate key:

• Out of all candidate key only one key gets selected as primary key then all the
remaining keys are called as alternate keys.
Eg:

• Aadhar no

Dept. of Computer Science 8 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
• Email id
5) Composite key:

• A key that have more than one attributes is know as composite key.
Eg:

• Rollno, Aadhar no
• Roll no, Name, Email id
Roll no Name Id
1 Robo 10
2 Robo 10

6) Foreign key:

• It is column pointer to the primary key of another table.

• It is generally a primary key from one table that appears a field to another
when the first table has relationship with records.

• It is used to maintain integrity of the data.

• This key is used to link two table together.


Foreign Key

Rno Sname Cid Cid Cname


101 Robo 10 10 Java
102 Sana 30 20 C
103 Chitti 10 30 C++

In the above table coursed is a foreign key.


Value Sets (Domains) Of Attributes
A set of values that may be assigned to the attributes of each individual entity, in
an entity set is called the Value set or Domain.
Example 1: For employee entity, if age limit is 20 to 58, then the values set (domain) of
attribute age consists of integers from 20 to 58. Age: Domain is [20 – 58]
Example 2: Similarly, the value set for name attribute could be a set of alphabets and
some special characters.

Dept. of Computer Science 9 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
Name: Domain is [a-z], [A-Z], blank space
Example 3: For salary attribute, the value set may be again a range from minimum of
5000 to maximum of 50000.
Weak Entity Types
Entity types that do not have key attributes of their own are called weak entity types.
They are sometimes known as child entity type or the subordinate entity type.
These entities are identified by being related to specific entities from another entity type
in combination with one of their attribute values. The other entity type is called the
identifying or owner entity type or parent entity type or dominant entity type. The
relationship type that relates a weak entity type always has a total participation
constraint with respect to its entity.
Entity types that have key attribute are called Strong entity types.
A weak entity type normally has a partial key, which is the set of attributes that can
uniquely identify weak entities that are related to the same owner entity. This partial key
is sometimes called the discriminator.
Example: The entity type DEPENDENT is related to EMPLOYEE. The attributes of
DEPENDENT are Name, Birthdate, Sex, Relationship to employee. Two dependents of
two distinct employees may by chance have same values but still they are distinct
entries. Then in that case, they are identified as distinct entities only after determining
the particular employee entity to which each dependent 1s related. Each employee entity
is said to own the dependent entities that are related to it.
A weak entity type and its identifying relationship are distinguished by surrounding
their boxes and diamonds with double lines. The partial key attribute is underlined with
a dashed or dotted line.
Types of Relationships
A Relationship describe on association among entities that is it tells how one
entity can be associated with other entities the association among entities is called
relationship.
Types of Relationships:
1. One to One Relationship: Only one entity of the First set is related to only one entity
of the Second set.
Ex: A teacher teaches a student. only one teacher is teaching only one student.

Student A 1
Teacher Teach
eses B 2

1 1

Dept. of Computer Science 10 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
2. One to Many Relationships: Only one entity of the First set is related to multiple
entities of the second set.
Ex: A teacher teaches students. only one teacher is teaching many students.

Teacher Teaches Student A 1

B 2

1 M
3. Many to one Relationship: Multiple entities of the first set are related to only one
entity.
Ex: Teacher teaches a student. Many teaches are teaching only one student.

Teacher Teaches Student A 1


es
B 2

M 1
4. Many to Many Relationships: Multiple entities of the First set one related to
multiple entities of the Second set.
Ex: Teacher teach students.
A 1
Teacher Teaches Student B 2
es

M M
Notation for ER Diagrams
The various notations used for E-R diagram are:
Symbols Description

Entity

Relationship

Attribute

Dept. of Computer Science 11 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari

Weak Entity

Weak Entity Relationship

Multivalued Attribute

Key Attribute

Composite Attribute

Degree of Relationship
➢ The number of entities participated in a relationship type defines the degree of
relationship.
There are 3 types of relationships.

1. Unary or Recursive Relationship:


➢ Unary relationship between the instance of a single entity type.
➢ The Degree of relationship is one.
Ex: 1 2

Is
Person Employee Manager
Married

mM
m
One to One One to Many

2. Binary Relationship:
➢ Binary relationship is a relationship between the instance of two entities type.
➢ The Degree of relationship is Two.

Dept. of Computer Science 12 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
Ex:

Author Write Books

One to Many

Student Learn Course

Many to Many
3. Ternary Relationship:
➢ Ternary Relationship is a relationship between the instance of three entities types.

e1 ------------------------- r1
e2 ------------------------- r2
e3 ------------------------- r3
e4 ------------------------- r4
e5 ------------------------- r5
e6 --------------------------r6
➢ The Degree of relationship is three.

Ex: University

College Certifica Student


te
Role names and Recursive Relationship: Each entity type participating in the
relationship will have a particular role in the relationship.
Ex: In the previous relationship of works-for, EMPLOYEE plays the role of a worker and
DEPARTMENT plays the role of an employer. In some cases, the same entity type
participates more than once in a relationship type in different roles. In such cases, roles
are given names to distinguish these roles and such relationship are called recursive.

Dept. of Computer Science 13 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
shows the recursive relationship, SUPERVISION, shows the relation between two entity
roles reply and supervisor, belonging to the same entity type. Hence, EMPLOYEE entity
participates twice in the relationship. SUPERVISION one is in the role of supervisor and
once in the role of supervisee. Lines indicate the role of the supervisor. of e2 and e4. e3
is the Supervisor of e5 and e6.
Constraints on Relationship Types: Usually there will be certain constraints on the
relationship type to limit the number of combinations of entities participating in the
relationship instances. For example, one of the constraints for the works-for relationship
could be that an employee can work for only one DEPARTMENT.
There are two types of structural constraints. They are:

• Cardinality ratio
• Participation
1. Cardinality ratio:
The cardinality ratio specifies the maximum number of relationship instances that an
entity can participate in.the possible cardinality ratios for binary relationship types are
1: N,1:1, N:1 and M: N
Consider the example of works-for relationship with the entity ratio
DEPARTMENT:EMPLOYEE which is given by 1: N .one department can have N
employees (one to many) and N employees can be related to only one department (N:1)
for an entity ratio EMPLOYEE:DEPARTMENT.
One can have 1:1 relationship if each department has only one employee who acts as
the manager of the department. the relation could be as follows: A department can have
only one manager and a manager can manage only one department. (one to one)
The ratio M:N means many persons can work on a single project and a single person
can work on many project (many to many).
2. Participation:
The participation constraint specifies whether the existence of an entity depends on
its being related to another entity via the relationship type. This constraint specifies the
minimum number of relationship instances that each entity can participate in, and is
sometimes called the minimum cardinality constraint.
There are two types of participation constraints:

• Total participation constraint


• Partial participation constraint

Dept. of Computer Science 14 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
1. Total participation constraint
For example: if the constraint is that every employee must work for the COMPANY,
then the entity EMPLOYEE exists only if it participates in the WORKS-FOR relationship.
Thus, the participation of EMPLOYEE in dependency. Employee e1 and e3 work for d1,
employee e2 and e3 work for d2 and e5 works for d3.

EMPLOYEE WORKS-FOR DEPARTMENT


e1 r1 d1
e2 r2 d2
e3 r3 d3
e4 r4
e5 r5
Partial participation constraint
Every employee does not manage a department.so the participation of EMPLOYEE in
the MANGES relationship type is partial. Employees e1, e4 do not manage a department.
only employees e2, e3 and e5 manage departments d1, d3 and d2 respectively.

EMPLOYEE WORKS-FOR DEPARTMENT


e1 r1 d1
e2 r2 d2
e3 r3 d3
e4 r4
e5 r5

Attributes of Relationship Types

Employee Works Department


For

Hours

Just like entities, relationship types can also have attributes. For example, in the
works-for relationship, we can add an attribute “hour”, which describes the relationship
as works-for so many hours.

Dept. of Computer Science 15 of 16 From the desk of Mr. Chaitanya Reddy Mtech
DBMS Shree Medha Degree College, Ballari
Consider the relationship between the entity sets EMPLOYEE POSITION. Let the
relation be DUTY-ALLOCATION and its attributes are and shift. The E-R diagram could
be as follows:

Duty
Employee Position
Allocation

Date Shift

Weak Entity Types:


➢ Entity types that do not have key attributes of their own are called weak entity types.
They are sometimes known as child entity type or the subordinate entity type.
➢ These entities are identified by being related to specific entities from another entity
type in combination with one of their attribute values. The other entity is called the
identifying or owner entity type or parent entity type always has a total participation
constraint with respect to its entity.
➢ A weak entity type normally has a partial key. Which is the set of attributes that can
uniquely identify weak entities that are related to the same owner entity. This partial
key is sometimes called the discriminator.
Example:
The entity type DEPARTMENT is related to EMPLOYEE the attributes of
DEPARTMENT are name, birthdate, sex, relationship to employee. Two dependents of
two distinct employees may be chance have same values but still they are distinct
entries. Then in that case, they are identified as distinct entities only for determing the
particular employee entity to which dependent is related. Each employee entity is said to
own the dependent entities that are related to it.
A weak entity type and its identifying relationship are distinguished by
surrounding their boxes and diamonds with double lines. The partial key attribute is
underlined with a dashed or dotted line.

Dept. of Computer Science 16 of 16 From the desk of Mr. Chaitanya Reddy Mtech

You might also like