0% found this document useful (0 votes)
36 views24 pages

Unit 2

Uploaded by

shaikhsubuktgin
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)
36 views24 pages

Unit 2

Uploaded by

shaikhsubuktgin
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
You are on page 1/ 24

Unit – II
2. E-R Data Models
2.1 Introduction :
• E-R stand for Entity Relationship Model.
• ER model was introduced by Peter Chenn in 1976.
• The ER model defines the Conceptual (or logical) view of database.
• It is used to designing database.
• It works around real-world entities and the relationships among them.
• A database schema in the ER Model can be represented pictorially as ER diagrams.
• An ER diagram maps well into a relational schema.

❖ Why ER Model is Useful ?
• An ER Model maps well to the relational model i.e. the constructs Used in ER Model can be
easily transformed into relational tables.
• An ER Model can be Used by the database designer to communicates the database design to the
user.
• An ER Model can be used as a design plan by the database developer to implement a data model
in specific DBMS software.

ER model contain three basic components,

1. Entity
2. Attributes
3. Relationships

1. Entity –
• An entity is objects that are represented in the database or an entity is a person or thing for which
data is collected and maintained.
• In ER model, an entity is represented using rectangles.

• Tangible: Entities which physically exit in real word.


• E.g: car, pen, bank_locker

• Intangible: Entities which exists logically.


• E.g: Account Name.
For example –
In a SCHOOL database, STDUENT can be considered as entity.

* Entity Set –
An entity set is a collection of similar types of entities. An entity set may contain entities with attribute
sharing similar values.

For example –
A STUDENTS set may contain all the students of a SCHOOL.

2. Attributes –
An attribute describes a property or characteristic of an entity or attributes are the properties of entities.
In an ER model, an attribute name appears in an oval or ellipse that has a line to the corresponding entity
box.

For example –
ROLLNO is an attribute of a STUDENT as shown in following figure:

* Types of Attributes –
1) Simple and Single Valued Attributes
2) Composite Attributes
3) Derived Attributes
4) Multi-Valued Attributes
5) Key Attribute

1) Simple and Single Valued Attributes –


Simple attributes are those attributes that are not divisible into subparts whereas single valued attributes
are those attributes that contains only atomic (single) values.

For example –
If we consider the ROLLNO, then ROLLNO is not divided into subparts, so it is a simple attribute as
well as it holds exactly one value thus, it is a single-valued attribute as shown in following figure,
2) Composite Attributes –
An attribute can also have their own attributes called as composite attribute or composite attributes are
those attributes that can be divided into subparts.

For example –
If we consider the NAME in two parts, FIRSTNAME & LASTNAME then the NAME attribute is a
composite as well as FIRSTNAME & LASTNAME are component attributes as shown in following figure,

Student

Name

F. N L.N

3) Derived Attributes –
Attributes which can be derived from some other attributes values are called derived attributes. Derived
attributes are denoted by Dashed-Oval Shaped Symbol.

For example –
The AGE of a student can be determined from the Date of Birth as shown in following figure,

4) Multivalued Attributes –
Attributes that have a set of values for a particular entity are called multivalued attributes. Multivalued
attribute is denoted by Double Oval Shaped Symbol.

For example –
The LAB_ASSISTANT attribute for the entity LABSECTION is multi-valued as shown in following
figure,
5) Key Attribute –
It represents primary key. It is an attribute that has unique value for each entity in an entity set.

For example –
ROLLNO is a key attribute in a STUDENT entity set as shown in following figure,
2.4 Constraints:
• Constraints enforce limits to the data or type of data that can be inserted/updated/deleted from a table.
• The whole purpose of constraints is to maintain the data integrity during an update/delete/insert into a
table.

Types of constraints

• NOT NULL
• UNIQUE
• DEFAULT
• CHECK
• Key Constraints – PRIMARY KEY, FOREIGN KEY

A) NOT NULL:

• NOT NULL constraint makes sure that a column does not hold NULL value.

• When we don’t provide value for a particular column while inserting a record into a table, it takes
NULL value by default.

• By specifying NULL constraint, we can be sure that a particular column(s) cannot have NULL values.

B) UNIQUE:

• UNIQUE Constraint enforces a column or set of columns to have unique values.


• If a column has a unique constraint, it means that particular column cannot have duplicate values in a
table.

C) DEFAULT:

• The DEFAULT constraint provides a default value to a column when there is no value provided while
inserting a record into a table.

D) CHECK:

• This constraint is used for specifying range of values for a particular column of a table.

• When this constraint is being set on a column, it ensures that the specified column must have the value
falling in the specified range.

E) Key constraints:
✓ PRIMARY KEY:

• Primary key uniquely identifies each record in a table. It must have unique values and cannot contain
nulls. (Unique + Not Null)

• In the below example the ROLL_NO field is marked as primary key, that means the ROLL_NO field
cannot have duplicate and null values.

✓ FOREIGN KEY:

• Foreign keys are the columns of a table that points to the primary key of another table. They act as a
cross-reference between tables.
Keys

• Key plays an important role in relational database; it is used for identifying unique rows from table.
• It also establishes relationship among tables.

Types of keys in DBMS

1. Primary Key – A primary is a column or set of columns in a table that uniquely identifies tuples (rows)
in that table.

2. Candidate Key – A super key with no redundant attribute is known as candidate key.

3. Super Key – A super key is a set of one of more columns (attributes) to uniquely identify rows in a table.

4. Alternate Key – Out of all candidate keys, only one gets selected as primary key, remaining keys are
known as alternate or secondary keys.

5. Composite Key – A key that consists of more than one attribute to uniquely identify rows (also known
as records & tuples) in a table is called composite key.

6. Foreign Key – Foreign keys are the columns of a table that points to the primary key of another table.
They act as a cross-reference between tables.
It is an attribute or set of attribute that refrences primery key of same table or others table(relation) .
2.5 What is an Entity Relationship Diagram (ER Diagram)?
• An ER diagram shows the relationship among entity sets.
• An entity set is a group of similar entities and these entities can have attributes.
• ER diagram shows the complete logical structure of a database.
• Lets have a look at a simple ER diagram to understand this concept.

A simple ER Diagram:
✓ In the following diagram we have two entities Student and College and their relationship.
✓ The relationship between Student and College is many to one as a college can have many students
however a student cannot study in multiple colleges at the same time.
✓ Student entity has attributes such as Stu_Id, Stu_Name & Stu_Addr and College entity has attributes
such as Col_ID & Col_Name.

Here are the geometric shapes and their meaning in an E-R Diagram. We will discuss these terms in detail in the next
section(Components of a ER Diagram) of this guide so don’t worry too much about these terms now, just go through them once.
Rectangle: Represents Entity sets

Ellipses/Oval:
Attributes

Diamonds: Relationship Set

Double Ellipses: Multivalued Attributes.

Double Rectangles: Weak Entity Sets

Dashed Ellipses: Derived Attributes

Lines:

They link attributes to Entity Sets and Entity sets to Relationship Set.

Double Lines:

Total participation of an entity in a relationship set.


2.6. Extended E-R Features:

1) Specialization –

• Specialization is opposite of Generalization.


• In Specialization, an entity is broken down into sub-entities based on their characteristics.
• Specialization is a "Top-down approach" where higher level entity is specialized into two or more lower
level entities.
• Specialization is used to identify the subset of an entity set that shares some distinguishing
characteristics.
• Specialization can be repeatedly applied to refine the design of schema
• depicted by triangle component labeled ISA.

Example: Specialization
Vehicle entity. can be a Car, Truck or Motorcycle.
Normally, the superclass is defined first, the subclass and its related attributes are defined next, and
relationship set are then added.
2)Generalization

• Generalization is the process of extracting common properties from a set of entities and create a
generalized entity from it.
• Generalization is a "bottom-up approach" in which two or more entities can be combined to form a
higher level entity if they have some attributes in common.
✓ subclasses are combined to make a superclass.

Example: Consider we have 3 sub entities Car, Bus and Motorcycle. Now these three entities can be generalized
into one higher-level entity (or super class) named as Vehicle.

2) Higher level and lower level entity sets –


• This property is created by specialization and generalization.
• The attributes of higher level entity sets are inherited by lower level entity sets.
For example: In above figure “customers” and “employee” inherits the attributes of “person”.

3) Attribute inheritance:
• When given entity set is involved as a lower entity set in only one is a relationship, it is referred as
a single attribute inheritance.
• If lower entity set is involved in more than one is a relationship, it is referred as a multi attribute
inheritance.
4) Aggregation:
• Aggregation is used when we need to express a relationship among relationships.
• Aggregation is an abstraction through which relationships are treated as higher level entities.
• Aggregation is a process when a relationship between two entities is considered as a single
entity and again this single entity has a relationship with another entity

Example: (Aggregation)

With Aggregation (without introducing redundancy) the ER diagram can be represented as:

✓ An employee works on a particular job at a particular branch.


✓ An employee, branch, job combination may have an associated manager
2.7. Example of E-R data dase design:
1) E-R digram for Banking System:

2) E-R digram for Tracher & Department:


3) E-R digram for Hotel Managenent:
4) E-R digram for university

You might also like