0% found this document useful (0 votes)
4 views

Introduction of ER Model

Uploaded by

bishwajeetit6331
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Introduction of ER Model

Uploaded by

bishwajeetit6331
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 83

Introduction of ER Model

The Entity Relational Model is a model for identifying entities to be represented in the
database and representation of how those entities are related. The ER data model specifies
enterprise schema that represents the overall logical structure of a database graphically.

The Entity Relationship Diagram explains the relationship among the entities present in the
database. ER models are used to model real-world objects like a person, a car, or a company
and the relation between these real-world objects. In short, the ER Diagram is the structural
format of the database.
Why Use ER Diagrams In DBMS?
1. ER diagrams are used to represent the E-R model in a database, which
makes them easy to convert into relations (tables).
2. ER diagrams provide the purpose of real-world modeling of objects
which makes them intently useful.
3. ER diagrams require no technical knowledge and no hardware support.
4. These diagrams are very easy to understand and easy to create even
for a naive user.
5. It gives a standard solution for visualizing the data logically.
Symbols Used in ER Model
• ER Model is used to model the logical view of the system from a data
perspective which consists of these symbols:
1. Rectangles: Rectangles represent Entities in the ER Model.
2. Ellipses: Ellipses represent Attributes in the ER Model.
3. Diamond: Diamonds represent Relationships among Entities.
4. Lines: Lines represent attributes to entities and entity sets with other
relationship types.
5. Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
6. Double Rectangle: Double Rectangle represents a Weak Entity.
Components of ER Diagram

• ER Model consists of Entities, Attributes, and Relationships among


Entities in a Database System.
Entity
• An Entity may be an object with a physical existence – a particular
person, car, house, or employee – or it may be an object with a
conceptual existence – a company, a job, or a university course.
• Entity Set: An Entity is an object of Entity Type and a set of all entities is
called an entity set. For Example, E1 is an entity having Entity Type
Student and the set of all students is called Entity Set. In ER diagram,
Entity Type is represented as:
What is Strong Entity?
• A strong entity is not dependent on any other entity in the schema. A strong
entity will always have a primary key. Strong entities are represented by a
single rectangle. The relationship of two strong entities is represented by a
single diamond. Various strong entities, when combined together, create a
strong entity set.
What is Weak Entity?
• A weak entity is dependent on a strong entity to ensure its existence. Unlike
a strong entity, a weak entity does not have any primary key. It instead has a
partial discriminator key. A weak entity is represented by a double
rectangle. The relation between one strong and one weak entity is
represented by a double diamond. This relationship is also known
as identifying relationship.
Difference between Strong and Weak Entity
• Attributes
• Attributes are the properties that define the entity type. For example,
Roll_No, Name, DOB, Age, Address, and Mobile_No are the attributes
that define entity type Student. In ER diagram, the attribute is represented
by an oval.
 Key Attribute
• The attribute which uniquely identifies each entity in the entity set is
called the key attribute. For example, Roll_No will be unique for each
student. In ER diagram, the key attribute is represented by an oval
with underlying lines.
Composite Attribute
• An attribute composed of many other attributes is called a composite
attribute. For example, the Address attribute of the student Entity type
consists of Street, City, State, and Country. In ER diagram, the
composite attribute is represented by an oval comprising of ovals.
Multivalued Attribute
• An attribute consisting of more than one value for a
given entity. For example, Phone_No (can be more than
one for a given student). In ER diagram, a multivalued
attribute is represented by a double oval.
 Derived Attribute
• An attribute that can be derived from other attributes of the entity type is
known as a derived attribute. e.g.; Age (can be derived from DOB). In ER
diagram, the derived attribute is represented by a dashed oval.
Relationship
• A relationship is used to describe the relation between entities.
Diamond or rhombus is used to represent the relationship.
One-to-One Relationship:
When only one instance of an entity is associated with the relationship,
then it is known as one to one relationship.
For example, A female can marry to one male, and a male can marry to
one female.
 One-to-many relationship
• When only one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then this
is known as a one-to-many relationship.
• For example, Scientist can invent many inventions, but the invention is
done by the only specific scientist.
Many-to-one relationship
• When more than one instance of the entity on the left, and only one instance of
an entity on the right associates with the relationship then it is known as a
many-to-one relationship.
• For example, Student enrolls for only one course, but a course can have many
students.
Many-to-many relationship
• When more than one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then it
is known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can
have many employees.
Notation of ER diagram
• Database can be represented using the notations. In ER diagram, many
notations are used to express the cardinality. These notations are as
follows:
• Steps to Create an ERD (E-R Digram) :
1. 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.
Step 1 Entity Identification
We have three entities
1. Student
2. Course
3. Professor
Step 2: Relationship Identification
We have the following two relationships
• The student is assigned a course
• Professor delivers a course
Step 3: Cardinality Identification
For them problem statement we know that,
1. A student can be assigned multiple courses
2. A Professor can deliver only one course
Step 4: Identify Attributes
• We 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, We 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.
Step 5: Create the ERD
• A more modern representation of ERD Diagram
This is an ER model of a Hospital. The entities are represented in
rectangular boxes and are Patient, Tests and Doctor.
Each of these entities have their respective attributes which are −
• Patients - ID(primary key), name, age,visit_date
• Tests- Name(primary key), date, result
• Doctor- ID(primary key), name, specialization
What is a Primary Key?
• A primary key is a column (or set of columns) in a table that
uniquely identifies each row in the table. It cannot contain null
values and must be unique across all rows in the table. Only one
primary key is allowed in a table.
• A primary key is basically a combination of the 'UNIQUE' and '
Not Null' constraints. Thus, it cannot be a NULL value. Another
important point to be noted about primary key is that its value
cannot be deleted from the parent table.
What is a Foreign Key?
• A foreign key is a column (or set of columns) in a table that refers to the
primary key in another table. It is used to establish a link between the two
tables and is used to enforce referential integrity in the database. Foreign key is
basically the field/column in a table that is analogous to the primary key of
other table.
• Unlike a primary key, a table can have more than one foreign key. Also, the
foreign key can contain duplicate and null values in a relational database. The
value of a foreign key can be deleted from the child table.
Key Primary Key Foreign Key

It is used to uniquely It is used to maintain


Basic identify data in the table. relationship between
tables.
It can't be NULL. It can accept the NULL
Null
values.
Two or more rows can't It can carry duplicate value
Duplicate have same primary key. for a foreign key attribute.

Primary has clustered By default, It is not


Index index. clustered index.

Primary key constraint can It can't be defined on


Tables be defined on temporary temporary tables.
table.
• StudentID | Name Age | Grade |
• |-----------|-----------|-----| -------|
• |1 | John | 18 | 12 |
• |2 | Emily | 17 | 11 |
• |3 | Michael | 18 | 12 |
• |4 | Sarah | 17 | 11 |
• Orders Table:
• | OrderID | CustomerID | OrderDate | TotalAmount |
• |---------|------------ |----------- |-------------|
• | 101 | 1 | 2024-04-15| 250.00 |
• | 102 | 2 | 2024-04-16| 150.00 |
• | 103 | 1 | 2024-04-17| 180.00 |

• Customers Table:
• | CustomerID | Name | Email | Phone |
• |------------ --------- |-------------------- |------------ -|
• |1 | Alice | [email protected] | 123-456-789 |
• |2 | Bob [email protected] | 987-654-321 |
CREATING A E-R DIAGRAM FROM RELATIONAL
SCHEMA.
• Exercise
• Draw an ERD for the following description: Each department has a
unique name, a unique number, and a particular employee who
manages the department. We keep track of the start date when that
employee began managing the department. A department may have
several locations
Specialization

• Specialization in Database Management Systems (DBMS) is the


reverse process of generalization. It is a top-down approach in which
an entity is divided into more specific sub-entities based on certain
distinguishing characteristics. This technique helps to model the
complex entities by breaking them down into smaller, specialized
entities, each of which has its own unique attributes
Key Points of Specialization:

1.Distinct Subsets: Specialized entities inherit the common properties of


the parent entity but have additional, specific attributes or relationships.
2.Top-Down Approach: It begins with a higher-level entity (general entity)
and then divides it into lower-level specialized entities.
3.ISA Relationship: There’s an “ISA” relationship between the parent and
the specialized entities, meaning each specialized entity "is a" type of
the general entity.
Problem:
• Consider a hospital management system where there is a general entity
called Person. The hospital staff consists of Doctors, Nurses, and
Administrative Staff, each with distinct roles and attributes. Perform
specialization to model this in an ER diagram.
Solution:
• General Entity (Superclass):
• Person: Common attributes such as Name, Address, Date_of_Birth,
Phone_Number.
• Specialized Entities (Subclasses):
• Doctor: Additional attributes such as Doctor_ID, Specialization, and
Years_of_Experience.
• Nurse: Additional attributes such as Nurse_ID, Shift, and
Ward_Assigned.
• AdminStaff: Additional attributes such as Admin_ID, Role, and Salary.
• Problem:
• A company’s employee database has a general entity Employee with
common attributes like Employee_ID, Name, Address, and
Phone_Number. The company has three types of employees: Full-Time
Employees, Part-Time Employees, and Contract Employees, each with
specific attributes. Use specialization to design this in an ER diagram.
• Solution:
• General Entity (Superclass):Employee: Attributes like Employee_ID,
Name, Address, and Phone_Number.
• Specialized Entities (Subclasses):
• Full TimeEmployee: Attributes like Salary and Benefits_Plan.
• Part TimeEmployee: Attributes like Hourly_Rate and Work_Hours.
• Contract Employee: Attributes like Contract_ID, Contract_Duration,
and Agency
• A bank has a general entity Account with attributes like
Account_Number, Balance, and Opening_Date. The bank offers
different types of accounts, such as Savings Account, Checking
Account, and Loan Account, each with specific attributes. Model this
using specialization.
Solution:
• General Entity (Superclass):Account: Common attributes like
Account_Number, Balance, and Opening_Date.
• Specialized Entities (Subclasses):
• SavingsAccount: Attributes like Interest_Rate and Withdrawal_Limit.
• CheckingAccount: Attributes like Overdraft_Limit and
Transaction_Fees.
• LoanAccount: Attributes like Loan_Amount, Interest_Rate, and
Repayment_Term
• Problem:
• In an e-commerce system, there is a general entity Product with attributes
like Product_ID, Name, and Price. The products are specialized into
Electronics, Clothing, and Grocery. Design an ER diagram using
specialization.
Solution:
• General Entity (Superclass):Product: Common attributes like Product_ID,
Name, and Price.Specialized Entities (Subclasses):
• Electronics: Attributes like Warranty_Period, Brand, and Model_Number.
• Clothing: Attributes like Size, Material, and Brand.
• Grocery: Attributes like Expiry_Date, Weight, and Packaging_Type.
Integrity Constraints
• Integrity constraints are a set of rules. It is used to maintain the quality of
information.
• Integrity constraints ensure that the data insertion, updating, and other
processes have to be performed in such a way that data integrity is not
affected.
• Thus, integrity constraint is used to guard against accidental damage to the
database.
Types of Integrity Constraint
Domain constraints

• Domain constraints can be defined as the definition of a valid set of


values for an attribute.
• The data type of domain includes string, character, integer, time, date,
currency, etc. The value of the attribute must be available in the
corresponding domain.
Entity integrity constraints
• The entity integrity constraint states that primary key value can't be
null.
• This is because the primary key value is used to identify individual rows
in relation and if the primary key has a null value, then we can't identify
those rows.
• A table can contain a null value other than the primary key field.
Referential Integrity Constraints
• A referential integrity constraint is specified between two tables.
• In the Referential integrity constraints, if a foreign key in Table 1
refers to the Primary Key of Table 2, then every value of the Foreign
Key in Table 1 must be null or be available in Table 2.
Key constraints
• Keys are the entity set that is used to identify an entity within its entity
set uniquely.
• An entity set can have multiple keys, but out of which one key will be the
primary key. A primary key can contain a unique and null value in the
relational table.
Join Operations:

and only if a given join condition is satisfied. It is denoted by ⋈.


• A Join operation combines related tuples from different relations, if
• Operation: (EMPLOYEE ⋈ SALARY)
Natural Join:
• A natural join is the set of tuples of all combinations in R and S that
are equal on their common attribute names.
• It is denoted by ⋈.
• Example: Let's use the above EMPLOYEE table and SALARY table:
Input:
• ∏EMP_NAME, SALARY (EMPLOYEE ⋈ SALARY)
2. Outer Join:
• The outer join operation is an extension of the join operation. It is used
to deal with missing information.
Input:
• (EMPLOYEE ⋈ FACT_WORKERS)
Left outer join:
• Left outer join contains the set of tuples of all combinations in R and S
that are equal on their common attribute names.
• In the left outer join, tuples in R have no matching tuples in S.
• It is denoted by ⟕.
Example: Using the above EMPLOYEE table and FACT_WORKERS
table
Input:
EMPLOYEE ⟕ FACT_WORKERS
Right outer join:
• Right outer join contains the set of tuples of all combinations in R and
S that are equal on their common attribute names.
• In right outer join, tuples in S have no matching tuples in R.
• It is denoted by ⟖.
• Example: Using the above EMPLOYEE table and FACT_WORKERS
Relation
Input:
• EMPLOYEE ⟖ FACT_WORKERS
Full outer join:
• Full outer join is like a left or right join except that it contains all rows
from both tables.
• In full outer join, tuples in R that have no matching tuples in S and
tuples in S that have no matching tuples in R in their common attribute
name.
• It is denoted by ⟗.
• Example: Using the above EMPLOYEE table and FACT_WORKERS
table
Input:
• EMPLOYEE ⟗ FACT_WORKERS
Equi join:
• It is also known as an inner join. It is the most common join. It is
based on matched data as per the equality condition. The equi join
uses the comparison operator(=).
• CUSTOMER ⋈ PRODUCT
Input:

You might also like