0% found this document useful (0 votes)
49 views55 pages

Entity-Relationship Model

In the above table, StudID is the primary key as it uniquely identifies each student record. Home Work Q. IDENTIFY PRIMARY KEY EmpID Name Department Salary 101 John HR 25000 102 Mark Finance 30000 103 Lisa Marketing 28000 104 Steve Sales 35000

Uploaded by

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

Entity-Relationship Model

In the above table, StudID is the primary key as it uniquely identifies each student record. Home Work Q. IDENTIFY PRIMARY KEY EmpID Name Department Salary 101 John HR 25000 102 Mark Finance 30000 103 Lisa Marketing 28000 104 Steve Sales 35000

Uploaded by

Raghav Nagpal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 55

Entity-Relationship Model

• Entity Sets
• Relationship Sets
• Mapping Constraints
• E-R Diagram
• Extended E-R Features
• Design of an E-R Database Schema
• Reduction of an E-R Schema to Tables
Entity Sets
• A database can be modeled as:
• a collection of entities,
• relationship among entities.
• An entity is an object that exists and is distinguishable from
other objects.
• Example: specific person, company, event, plant
• Entities have attributes
• Example: people have names and addresses
• An entity set or entity type is a set of entities of the same type
that share the same properties.
• Example: set of all persons, companies, trees, holidays
Entity Sets customer and loan
customer-id customer- customer- customer- loan- amount
name street city number
Attributes
• An entity is represented by a set of attributes, that is descriptive
properties possessed by all members of an entity set.
Example:
customer = (customer-id, customer-name,
customer-street, customer-city)
loan = (loan-number, amount)
• Domain – the set of permitted values for each attribute
Types of Attributes-
1. Simple attributes
2. Composite attributes
3. Single valued attributes
4. Multi valued attributes
5. Derived attributes
6. Key attributes
1. Simple Attributes-

• Simple attributes are those attributes which can not be


divided further.
• Example-

• Here, all the attributes are simple attributes as they can not
be divided further.
2. Composite Attributes-

• Composite attributes are those attributes which are composed


of many other simple attributes.
• Example-

• Here, the attributes “Name” and “Address” are composite


attributes as they are composed of many other simple
attributes.
3. Single Valued Attributes-

• Single valued attributes are those attributes which can take


only one value for a given entity from an entity set.
• Example-

• Here, all the attributes are single valued attributes as they can
take only one specific value for each entity.
4. Multi Valued Attributes-

• Multi valued attributes are those attributes which can take


more than one value for a given entity from an entity set.
• Example-

• Here, the attributes “Mob_no” and “Email_id” are multi


valued attributes as they can take more than one values for a
given entity.
5. Derived Attributes-

• Derived attributes are those attributes which can be derived


from other attribute(s).
• Example-

• Here, the attribute “Age” is a derived attribute as it can be


derived from the attribute “DOB”.
6. Key Attributes-

• Key attributes are those attributes which can identify an entity


uniquely in an entity set.
• Example-

• Here, the attribute “Roll_no” is a key attribute as it can


identify any student uniquely.
Relationship Sets
• A relationship is an association among several entities
Example:
Roles
• Entity sets of a relationship need not be distinct
• The labels “manager” and “worker” are called roles; they specify how
employee entities interact via the works-for relationship set.
• Roles are indicated in E-R diagrams by labeling the lines that connect
diamonds to rectangles.
• Role labels are optional, and are used to clarify semantics of the relationship
• RECURSIVE ROLES:
• However, in some cases the same entity type participates
more than once in a relationship type in different roles. In such
cases the role name becomes essential for distinguishing the
meaning of each participation. Such relationship types are
called recursive relationships,
EMPLOYEE SUPERVISION

2 r1
e1
1

e2 r2
1

e3 2 r3
1
e4 2 r4

e5 r5
Degree of a Relationship Set
• Refers to number of entity sets that participate in a relationship
set.
• Relationship sets that involve two entity sets are binary (or
degree two). Relationship sets that involve three entity sets are
ternary Generally, most relationship sets in a database system are
binary.
• Relationship sets may involve more than two entity sets.
E.g. Suppose employees of a bank may have jobs
(responsibilities) at multiple branches, with different jobs at
different branches. Then there is a ternary relationship set
between entity sets employee, job and branch
• Relationships between more than two entity sets are rare. Most
relationships are binary. (More on this later.)
Mapping Cardinalities or Cardinality
Ratio
• Express the number of entities to which another entity can
be associated via a relationship set.
• Most useful in describing binary relationship sets.
• For a binary relationship set the mapping cardinality must be
one of the following types:
• One to one
• One to many
• Many to one
• Many to many
Mapping Cardinalities

One to one One to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
Mapping Cardinalities

Many to one Many to many


Note: Some elements in A and B may not be mapped to any
elements in the other set
EXAMPLES

MANAGES, a 1:1 relationship type between EMPLOYEE and


DEPARTMENT.

WORKS_FOR, a 1:N relationship type between DEPARTMENT and


EMPLOYEE.

CONTROLS, a 1:N relationship type between DEPARTMENT and


PROJECT

SUPERVISION, a 1:N relationship type between EMPLOYEE (in the


supervisor role) and EMPLOYEE (in the supervisee role).

WORKS_ON, determined to be an M:N relationship type with


PROJECT and EMPLOYEE.
Relationship Sets with
Attributes
Cardinality Constraints
• We express cardinality constraints by drawing either a directed
line (), signifying “one,” or an undirected line (—), signifying
“many,” between the relationship set and the entity set.
• E.g.: One-to-one relationship:
• A customer is associated with at most one loan via the relationship
borrower
• A loan is associated with at most one customer via borrower
One-To-Many Relationship
• In the one-to-many relationship a loan is associated with at
most one customer via borrower, a customer is associated with
several loans via borrower
Many-To-One Relationships
• In a many-to-one relationship a loan is associated with several
customers via borrower, a customer is associated with at most
one loan via borrower
Many-To-Many Relationship

• A customer is associated with several loans via borrower


• A loan is associated with several customers via borrower
Participation of an Entity Set in a Relationship Set
 Total participation (indicated by double line): every entity in the entity
set participates in at least one relationship in the relationship set
 E.g. participation of loan in borrower is total
 every loan must have a customer associated to it via borrower
 Partial participation: some entities may not participate in any
relationship in the relationship set
 E.g. participation of customer in borrower is partial
keys in DBMS
• A DBMS key is an attribute or set of an attribute which
helps you to identify a row(tuple) in a relation(table).

• They allow you to find the relation between two tables.


Keys help you uniquely identify a row in a table by a
combination of one or more columns in that table.
Example:
Employee ID FirstName LastName
11 Andrew Johnson
22 Tom Wood
33 Alex Hale

In the above-given example


• employee ID is a primary key because it uniquely identifies an
employee record.
• In this table, no other employee can have the same employee ID.
Why we need a Key?

reasons for using Keys in the DBMS system.


• Keys help you to identify any row of data in a table.
• In a real-world application, a table could contain thousands of
records.
• Moreover, the records could be duplicated. Keys ensure that
you can uniquely identify a table record despite these
challenges.
Various Keys in Database
Management System
• DBMS has followling seven types of Keys each have their
different functionality:
1. Super Key
2. Primary Key
3. Candidate Key
4. Alternate Key
5. Foreign Key
6. Composite Key
7. Surrogate Key
What is the Super key?

• It is defined as a group of single or multiple attributes within a


table that can uniquely identified a record in a table.
Example:

EmpSN EmpNum Empname


9812345098 AB05 Smith
9876512345 AB06 Roslyn
199937890 AB07 James

In the above-given example, EmpSN and EmpNum name are


superkeys
Home Work
Q. IDENTIFY SUPERKEYS

S_ID NAME PHONE_NUMBER AGE


1 AKHIL 9843876545 20
2 AKHIL 9867554324 22
3 BHANU 8735242637 21
4 PRIYA 6557382922 20
What is a Primary Key?

• A column or group of columns in a table which helps us to


uniquely identifies every row in that table is called a primary
key.
• Primary can't be a duplicate. The same value can't appear
more than once in the table.
Rules for defining Primary key:
• Two rows can't have the same primary key value
• The primary key field cannot be null.
• The value in a primary key column can never be modified or
updated if any foreign key refers to that primary key.
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

In the above following example: StudID is a Primary Key.


What is the Alternate key?

• All the keys which are not primary key are called an alternate
key.
• It is a candidate key which is currently not the primary key.
However, A table may have single or multiple choices for the
primary key.
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

• StudID, Roll No, Email are qualified to become a primary key.


• But since StudID is the primary key, Roll No, Email becomes the alternative key.
What is a Candidate Key?

• A super key with no repeated attribute is called candidate key.


• The Primary key should be selected from the candidate keys.
Every table must have at least a single candidate key.
Properties of Candidate key:
• It must contain unique values
• Candidate key may have multiple attributes
• Must not contain null values
• Uniquely identify each record in a table
Example:
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

• In the given above table Stud ID, Roll No, and Email are candidate keys
which help us to uniquely identify the student record in the table.
What is the Foreign key?

• A foreign key is a column which is added to create a


relationship with another table.
• Foreign keys help us to maintain data integrity and also allows
navigation between two different instances of an entity.
• Every relationship in the model needs to be supported by a
foreign key.
Example:
Table1:Department

DeptCode DeptName
001 Science
002 English
005 Computer
Table2:Teacher

Teacher ID Fname Lname


B002 David Warner
B017 Sara Joseph
B009 Mike Brunton
• In previous table, adding the foreign key in Deptcode to the
Teacher name, we can create a relationship between the two
tables.

Teacher ID DeptCode Fname Lname


B002 002 David Warner
B017 002 Sara Joseph
B009 001 Mike Brunton

• This concept is also known as Referential Integrity.


What is the Compound key?

• If we use multiple attributes to create a primary key then that


primary key is called composite key or compound or
concatenate key.
Example
Cust_id Order_id Sale_details
A001 001 Reached
A002 002 Not reached
What is a Surrogate Key?
• An artificial key which aims to uniquely identify each record is
called a surrogate key.
• These kind of key are unique because they are created when
you don't have any natural primary key.
• They do not lend any meaning to the data in the table.
Surrogate key is usually an integer.

• CHAUDHARY RAVI KUMAR


Example
Fname Lastname Start Time End Time
Anne Smith 09:00 18:00
Jack Francis 08:00 17:00
Anna McLean 11:00 20:00
Shown Willam 14:00 23:00

• Above, given example, shown shift timings of the different


employee.
• In this example, a surrogate key is needed to uniquely identify each
employee.
• In the table when the primary key is too big or complicated.
Weak Entity Sets (Cont.)
• We depict a weak entity set by double rectangles.
• We underline the discriminator of a weak entity set with a
dashed line.
• payment-number – discriminator of the payment entity set
• Primary key for payment – (loan-number, payment-number)
ER MODEL NOTATIONS
E-R Diagram for a Banking
Enterprise
E-R Diagrams

 Rectangles represent entity sets.


 Diamonds represent relationship sets.
 Lines link attributes to entity sets and entity sets to relationship sets.
 Ellipses represent attributes
 Double ellipses represent multivalued attributes.
 Dashed ellipses denote derived attributes.
 Underline indicates primary key attributes (will study later)
E-R Diagram With Composite, Multivalued, and Derived Attributes
How about doing
another ER design
interactively on the
board?
Summary of Symbols Used in E-R
Notation

You might also like