Professional Documents
Culture Documents
▪ ER Model Basics
• Entity
• Entity Type
• Attribute
• Attribute Type
• Key and Key Attributes
• Relationship
• ER Diagram Example
▪ References
ER MODELING -TOP DOWN APPROACH
▪Entity:
• Real-world object distinguishable from other objects.
• E.g. customers, accounts, bank branch
▪Entity Set:
• A collection of similar entities. E.g., all employees.
Attributes
• e.g. :The domain of the attribute “month” is having twelve values ranging from
January to December.
Attributes Types
Types of Attributes Definition Example
Address of the
Composite attribute Can be split into components
employee
Composite attribute
Represented by an ellipse from which other ellipses emanate and represent the
component attributes. E.g Address
Key Attributes
▪ Weak entity: Entity that depends on other entity for its existence
and doesn’t have key attribute (s) of its own.
• e.g. : spouse of employee
ER MODELING - NOTATIONS
Attributes of a Relationship
These attributes best describe the relationship prescription rather than any
individual entity Doctor, Patient or Medicine.
Degree of a Relationship
▪ e.g.:
1.employee manager-of employee is unary
2.employee works-for department is binary
3.Customer purchases items from a shopkeeper (a relationship in
which 3 entities are participating is called Ternary relationship)
• Here customer purchase item, shop keeper is a ternary
relationship
ER MODELING - NOTATIONS
Unary Relationship
• A unary relationship is represented as a diamond which connects one entity to itself as a loop.
• The relationship above means, some instances of employee manage other instances of
Employee.
ER MODELING - NOTATIONS
Binary Relationship
Ternary Relationship
▪ e.g.:
• Employee head-of department (1:1)
• Lecturer offers course (1:N) assuming a course is taught by a single lecturer
• Student enrolls course (M:N)
▪ The minimum and maximum values of this connectivity is called the cardinality of the relationship.
▪ Cardinality defines the possible number of occurrences in one entity which is associated with the
number of occurrences in another. For example, ONE team has MANY players. When present in an
ERD, the entity Team and Player are inter-connected with a one-to-many relationship.
Relationship Participation
Relationship participation
•All instances of the entity type Employee don’t participate in the relationship, Head-of.
•Every employee doesn’t head a department. So, employee entity type is said to partially participate in the relationship.
•But, every department would be headed by some employee.
•So, all instances of the entity type Department participate in this relationship. So, we say that it is total participation from the
department side.
ER MODELING - NOTATIONS
▪ Sometimes the value to be inserted into a particular cell may be unknown, or it may
have no value.
▪ This is represented by a NULL
▪ Null is not the same as zero, blank or an empty string
Key in a Relation
1. Super Key:
BookID Name Author
▪ a set of attributes which specifies that no two tuples (of a relation) is same.
OR 1001 X D1
‘K’ is the super key of a Schema ‘R’ if values for k are sufficient to identify 1002 Y D2
unique tuple of each possible relation r(R).
1003 X D3
▪ No two tuples can have same values for super key.
1004 M D1
▪ Super set of super key is also a super key.
2. Candidate Key:
BookID Name Author
▪ Minimal super key (super key without redundancy) is known as Candidate Key. 1001 X D1
▪ A Candidate key is not reducible as it has no redundancy.
▪ However, any subset of these set of attributes would not identify a row 1002 Y D2
uniquely
1003 X D3
▪ There can be more than one candidate keys in a relation.
▪ Overlapping candidate keys: Two candidate keys overlap if they involve any 1004 M D1
attribute in common.
▪ Key Attributes:
• The attributes that participate in the Candidate key are Key attributes
▪ Non-Key Attributes:
• The attributes which do not participate in the Candidate key.
Types Of Keys
Primary key:
▪ During the creation of the table, the Database Designer chooses one of the Candidate
Key amongst the several available, to uniquely identify row in the given table.
▪ The candidate key that is chosen to perform the identification task is called the
primary key
▪ Composite primary key : A primary key which is a combination of more than one
attribute.
▪ Every tuple must have, by definition, a unique value for its primary key.
▪ While Selecting Primary Key:
• Give preference to numeric column(s)
• Give preference to single attribute
• Give preference to minimal composite key
Types Of Keys
Alternate Key:
▪ The candidate key that is chosen to perform the identification task is
called the primary key and the remaining candidate keys are known
as alternate keys.
▪ No of Alternate Keys = No of Candidate Keys - 1
EXAMPLE
Relationship Between Keys
Primary Key
Candidate Key
Super Key
Types Of Keys
Foreign key
▪ This key established relation between two tables (relation).
▪ A Foreign Key is a set of attribute (s) of a table, whose values are required to match values of some Candidate
Key in the same or another table
▪ Usually a foreign key is a “copy” of a primary key that has been exported from one relation into another to
represent the existence of a relationship between them.
▪ Foreign Key column must match the values of the corresponding Candidate Key column. This is known as
Referential constraint.
▪ A table which has a Foreign Key referring to its own Candidate Key is known as Self-Referencing table
▪ Foreign key is used to keep database small and to reduce redundancy.
▪ To enter the data in child table corresponding data must be present in master table
or NULL is the default entry in child table in the referenced column ( FK column)
▪ Foreign key values do not (usually) have to be unique.
▪ Foreign keys can also be null .
DEPT EMP
(Parent /Master/Referenced Table) (Child /Referencing Table)
1004 Maida D1
DEPT TABLE HAS DEPTNO AS PRIMARY
KEY
EMP TABLE HAS ALSO DEPTNO BUT HERE
IT IS FOREIGN KEY
TOPIC:
EXTENDED E-R MODEL FEATURE-
GENERALIZATION AND
SPECIALIZATION
INTRODUCTION:
• Attributes->{person_id,name,street,city}
person
A person can be further classified into following entity sets:
• customer
Attributes ->{customer_id,customer_name,customer_street,
customer_city,credit_rating}
customer
• employee
Attributes ->{employee_id, employee_name,employee_street,
employee_city,salary}
employee
• The process of designing subgroupings within an entity set is called specialization.
person
ISA
employee customer
We can apply specialization repeatedly to refine a design scheme.
• For example : employee can be further classified as follows:
• officer
Attributes ->{officer_id, officer_name, officer_street,
officer_city,officer_salary,office_number}
• teller
Attributes ->{teller_id, teller_name, teller_street, teller_city,
teller_salary,station_number,hours_worked}
• secretary
Attributes ->{secretary_id, secretary_name, secretary_street, secretary_city,
secretary_salary,hours_worked}
• It can be represented as follows:
employee
ISA