Professional Documents
Culture Documents
• Security design
• Provides authentication
Steps in Designing an Entity-Relationship Schema
Id Gpa
Students Courses
Enrolled_In
Grade
ER model example
ER diagram for hospital management system
ER MODEL
Entity
• An entity is an object in real world which is distinguishable from other
• Entities are represented in the ER Diagram by a rectangular box.
Entity set
An entity set is a set of same type of entities.
Student, employee
Entity Sets-
Strong entity set
A strong entity set is an entity set that contains sufficient attributes to
uniquely identify all its entities.
In other words, a primary key exists for a strong entity set.
Primary key of a strong entity set is represented by underlining it.
Strong entity set
Weak entity set
• A weak entity set is an entity set that does not contain sufficient
attributes to uniquely identify its entities.
• In other words, a primary key does not exist for a weak entity set.
• However, it contains a partial key called as a discriminator.
• Discriminator can identify a group of entities from the entity set.
• Discriminator is represented by underlining with a dashed line.
Weak entity set
Strong entity set vs weak entity set
Strong entity set Weak entity set
A single rectangle is used for the representation of A double rectangle is used for the representation
a strong entity set. of a weak entity set.
It contains sufficient attributes to form its primary It does not contain sufficient attributes to form its
key. primary key.
A diamond symbol is used for the representation A double diamond symbol is used for the
of the relationship that exists between the two representation of the identifying relationship that
strong entity sets. exists between the strong and weak entity set.
A single line is used for the representation of the A double line is used for the representation of the
connection between the strong entity set and the connection between the weak entity set and the
relationship. relationship set.
Total participation may or may not exist in the Total participation always exists in the identifying
relationship. relationship.
Attribute
Attribute is a characteristic/property of an entity.
Attributes are represented in the ER Diagram by a oval or ellipse.
Attributes
Attributes
Key attribute
The key attribute is used to represent the main characteristics of an
entity. It represents a primary key. The key attribute is represented by
an ellipse with the text underlined.
Composite attributes
• Composite attributes can be divided into smaller subparts, which represent more basic attributes with
independent meanings.
Simple attributes
• Attributes that are not divisible are called simple or atomic attributes.
Single valued attributes, multivalued attributes
Most attributes have a single value for a particular entity such attributes are called single-valued attribute.
The number of different entity sets participating in a relationship set is called as degree of a relationship set.
Unary relationship: When there is only ONE entity set participating in a relation, the relationship
is called as unary relationship.
Binary relationship:When there are TWO entity sets participating in a relation, the relationship is
called as binary relationship.
Ternary relationship:When there are THREE entity sets participating in a relation, the relationship
is called as binary relationship
Unary relationship
Binary relationship
Ternary relationship
Participation constraints
Total participation constraint
It specifies that each entity in the entity set must compulsorily
participate in at least one relationship instance in that relationship set
Total participation is represented using a double line between the
entity set and relationship set.
Partial participation
It specifies that each entity in the entity set may or may not participate
in the relationship instance in that relationship set.
It is also called as optional participation.
Partial participation is represented using a single line between the
entity set and relationship set.
Cardinality/mapping cardinality constraints
The number of times an entity of an entity set participates in a relationship set is known as cardinality.
One to one relationship
An entity in set A can be associated with at most one entity in set B.
An entity in set B can be associated with at most one entity in set A.
An entity in set A can be associated with any number (zero or more) of entities in set B.
An entity in set B can be associated with any number (zero or more) of entities in set A.
Additional features of ER Model
• Key constraints
• Participation constraints
• Weak entities
• Class hierarchies(generalization, specialization)
• Aggregation
Key Constraints name
since
dname
ssn lot did budget
• Consider Works_In: An
employee can work in many Employees Manages Departments
departments; a dept can have Key Constraint
many employees.
• In contrast, each dept has at
most one manager, according
to the key constraint on
Manages.
Partial participation
It specifies that each entity in the entity set may or may not participate
in the relationship instance in that relationship set.
It is also called as optional participation.
Partial participation is represented using a single line between the
entity set and relationship set.
Participation Constraints
• Does every department have a manager?
• If so, this is a participation constraint: the participation of Departments in Manages is
said to be total (vs. partial).
• Every did value in Departments table must appear in a row of the Manages table (with
a non-null ssn value!)
since
name dname
ssn lot did budget
since
Weak entity set
A weak entity set is an entity set that does not contain sufficient
attributes to uniquely identify its entities.
In other words, a primary key does not exist for a weak entity set.
However, it contains a partial key called as a discriminator.
Discriminator can identify a group of entities from the entity set.
Discriminator is represented by underlining with a dashed line.
Weak Entities
A weak entity can be identified uniquely only by considering the primary key of
another (owner) entity.
Owner entity set and weak entity set must participate in a one-to-many relationship set (1
owner, many weak entities).
Weak entity set must have total participation in this identifying relationship set.
name
cost pname age
ssn lot
Primary Key
for weak entity
Employees Policy Dependents
• An ER diagram is not capable of representing relationship between an entity and a relationship which may be
required in some scenarios. In those cases, a relationship with its corresponding entities is aggregated into a
higher level entity
• Aggregation is an abstraction through which relationships are treated as higher level entities.
name
ssn lot
Aggregation Employees
• Given below are the examples of super keys since each set can
uniquely identify each student in the Student table-
• ( roll , name , gender, age , address , class , section )
• ( class , section , roll )
• (class , section , roll , gender)
Candidate key
A set of minimal attributes that can identify each tuple uniquely in the
given relation is called as a candidate key.
•
• Consider the following Student schema-
• Student ( roll , name , gender, age , address , class , section )
•
• Given below are the examples of candidate keys since each set consists of
minimal attributes required to identify each student uniquely in the
Student table-
• ( class , section , roll )
Candidate key
• All the attributes in a candidate key are sufficient as well as necessary to
identify each tuple uniquely.
• Removing any attribute from the candidate key fails in identifying each tuple
uniquely.
• The value of candidate key must always be unique.
• The value of candidate key can never be NULL.
• It is possible to have multiple candidate keys in a relation.
• Those attributes which appears in some candidate key are called as prime
attributes.
•
Primary key
• It is the minimal of candidate key.
• The value of primary key can never be NULL.
• The value of primary key must always be unique.
• The values of primary key can never be changed i.e. no updation is
possible.
• The value of primary key must be assigned when inserting a record.
• A relation is allowed to have only one primary key.
keys
Alternate key
• A candidate key not selected as a primary key is called
alternate or secondary key.
Foreign key
• It references the primary key in another table.
Foreign key
An attribute ‘X’ is called as a foreign key to some other attribute ‘Y’
when its values are dependent on the values of attribute ‘Y’.
The attribute ‘X’ can assume only those values which are assumed by
the attribute ‘Y’.
Here, the relation in which attribute ‘Y’ is present is called as
the referenced relation.
The relation in which attribute ‘X’ is present is called as
the referencing relation.
The attribute ‘Y’ might be present in the same table or in some other
table.
Foreign key
• Foreign key references the primary key of the table.
• Foreign key can take only those values which are present in the primary key
of the referenced relation.
• Foreign key may have a name other than that of a primary key.
• Foreign key can take the NULL value.
• There is no restriction on a foreign key to be unique.
• In fact, foreign key is not unique most of the time.
• Referenced relation may also be called as the master table or primary table.
• Referencing relation may also be called as the foreign table.
Partial key
Partial key is a key using which all the records of the table can not be
identified uniquely.
However, a bunch of related tuples can be selected from the table
using the partial key.
Partial key
Department ( Emp_no , Dependent_name , Relation )
Here, using partial key Emp_no, we can not identify a tuple uniquely but we can select a bunch of tuples from the table.
E1 Suman Mother
E1 Ajay Father
E2 Vijay Father
E2 Ankush Son
Composite Key
from Duration to
Binary vs. Ternary Relationships name
ssn lot pname age
• If each policy is owned by Employees Dependents
Covers
just 1 employee:
• Key constraint on Policies Bad design
Policies
would mean policy can only
cover 1 dependent! policyid cost
Purchaser
Beneficiary
Better design
Policies
policyid cost