CS 4002 Unit - 2 Data Modelling Using ER Model (Part - B)
CS 4002 Unit - 2 Data Modelling Using ER Model (Part - B)
Unit 2 – Part b
Table of Contents
1) MAPPING CARDANALITIES ............................................................................................................................. 2
• One-to-One .......................................................................................................................................................... 2
• One-to-Many ....................................................................................................................................................... 2
• Many -to- One...................................................................................................................................................... 2
• Many -to- Many................................................................................................................................................... 3
2) KEYS ........................................................................................................................................................................ 3
• Super Key ............................................................................................................................................................ 3
• Candidate Key ..................................................................................................................................................... 4
• Alternate Key....................................................................................................................................................... 5
• Primary Key ........................................................................................................................................................ 6
• Composite Key..................................................................................................................................................... 7
• Foreign Key ......................................................................................................................................................... 8
3) Strong and Weak Entity Sets ............................................................................................................................... 10
• Strong Entity Set ............................................................................................................................................... 10
• Weak Entity Set................................................................................................................................................. 10
• Strong v/s Weak Entity Set .............................................................................................................................. 10
4) EXTENDED ER FEATUES ................................................................................................................................ 11
• Specialization ..................................................................................................................................................... 11
• Generalization ................................................................................................................................................... 12
• Attribute Inheritance ........................................................................................................................................ 13
• Aggregation ....................................................................................................................................................... 13
----------------------------------------------------------------------------------------------------------------
Page 1
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
1) MAPPING CARDANALITIES
• Mapping cardinalities, or cardinality ratios, express the number of entities to which
another entity can be associated via a relationship set. Mapping cardinalities are most
useful in describing binary relationship sets, although they can contribute to the
description of relationship sets that involve more than two entity sets.
• For a binary relationship set R between entity sets A and B, the mapping cardinality
must be one of the following:
• One-to-One
An entity in A is associated with at most one entity in B,
and an entity in B is associated with at most one entity in
A.
• One-to-Many
An entity in A is associated with any number (zero or
more) of entities in B. An entity in B, however, can be
associated with at most one entity in A.
Page 2
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
2) KEYS
• Super Key
o We can define a super key as a set of those keys that identify a row or a tuple
uniquely.
o The word super denotes the superiority of a key.
o Thus, a super key is the superset of a key known as a Candidate key.
o Role of Super Key :-
▪ The role of the super key is simply to identify the tuples of the specified
table in the database.
▪ It is the superset where the candidate key is a part of the super key only.
▪ So, all those attributes in a table that is capable of identifying the other
attributes of the table in a unique manner are all super keys.
o Example of a Super Key
▪ Let's consider an EMPLOYEE_DETAIL table example where we have the
following attribute:
Page 3
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
• Candidate Key
o A candidate key is a part of a key known as Super Key (discussed in the
previous section), where the super key is the super set of all those attributes that
can uniquely identify a table.
o What is Candidate key?
▪ A candidate key is a subset of a super key set where the key which contains
no redundant attribute is none other than a Candidate Key.
▪ In order to select the candidate keys from the set of super key, we need to
look at the super key set.
o Role of Candidate Key :-
▪ The role of a candidate key is to identify a table row or column uniquely.
Also, the value of a candidate key cannot be Null.
▪ The description of a candidate key is "no redundant attributes" and being a
"minimal representation of a tuple," according to the Experts.
o How a Candidate key is different from a Primary Key ?
▪ Although the purpose of both candidate and the primary key is the same,
that is to uniquely identify the tuples, and then also they are different from
each other.
▪ It is because, in a table, we can have one or more than one candidate key,
but we can create only one primary key for a table.
▪ Thus, from the number of obtained candidate keys, we can identify the
appropriate primary key.
▪ However, if there is only one candidate key in a table, then it can be
considered for both key constraints.
o Example of a Candidate Key
▪ Consider an EMPLOYEE_DETAIL table where we have the following
attributes:
Page 4
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
• Alternate Key
o An alternate key is the secondary candidate key that contains all the property of
a candidate key but is an alternate option.
o An alternate is a secondary candidate key that is capable of identifying a row
uniquely.
o However, such a key is not used as a primary key because out of all the
generated candidate keys, only one key is selected as the primary key.
o Thus, the other remaining keys are known as Alternate Keys or Secondary
Keys.
o Use of Alternate Key :-
▪ An alternate key is none other than a candidate key, so the use/role of an
alternate key is the same.
▪ It means an alternate key is also used to identify those columns in a table
that can uniquely identify all the records of the table.
o Example of an Alternate Key
▪ Consider another example of Student_Detail, where we have the
following attributes:
Page 5
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
Page 6
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
➢ NON NULL Value: The primary key must have a non-null value for
each tuple of the relation, which is required for the identification of the
tuple.
➢ Time Variant: The values of the primary key must not change or
become null during the time of a relation.
➢ Unique: The value of the primary key must not be duplicated in any of
the tuples of a relation.
o Example of a Primary Key
▪ Below is the table named STUDENT_DETAILS, where Roll_no, Name, and
Marks are the specified attributes of it.
▪ As we know that from these three attributes, the Roll_no attribute is the
one that can uniquely identify other two attributes of the table as each
student is provided with a unique roll number in every organization.
▪ So, we can set the primary key constraint on the Roll_no column.
• Composite Key
o A 'combination of two or more' better describes the word 'composite'.
o Thus, a composite key in DBMS is a candidate key that is composed of two or
more attributes and is capable of uniquely identifying a table or a relation.
o What is Composite Key ?
▪ A composite key is the DBMS key having two or more attributes that
together can uniquely identify a tuple in a table. Such a key is also known
as Compound Key, where each attribute creating a key is a foreign key in
its own right.
o Use of Composite key :-.
▪ Two or more attributes together form a composite key that can uniquely
identify a tuple in a table.
▪ We need to find out such table columns combination that can form a
candidate key and hence a composite key.
o Example of a Composite Key
▪ Below is an example to understand the working of a composite key.
Page 7
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
▪ Thus, it is used for creating and maintaining the relationship between the
two relations.
o Example of a Foreign Key :-
▪ Consider two tables Student and Department having their respective
attributes as shown in the below table structure:
▪ In the tables, one attribute, you can see, is common, that is Stud_Id, but it
has different key constraints for both tables.
▪ In the Student table, the field Stud_Id is a primary key because it is
uniquely identifying all other fields of the Student table.
▪ On the other hand, Stud_Id is a foreign key attribute for the Department
table because it is acting as a primary key attribute for the Student table.
▪ It means that both the Student and Department table are linked with one
another because of the Stud_Id attribute.
▪ In the below-shown figure, you can view the following structure of the
relationship between the two tables.
Page 9
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
o The relation between one strong and one weak entity is represented by a double
diamond.
o This relationship is also known as identifying relationship.
• Strong v/s Weak Entity Set
4) EXTENDED ER FEATUES
• Some aspects of a database may be more aptly expressed by certain extensions to the
basic E-R model.
• We would consider the example of a university by defining an entity set person,
with attributes ID, name, street, and city.
• Specialization
o An entity set may include subgroupings of entities that are distinct in some way
from other entities in the set.
o For instance, a subset of entities within an entity set may have attributes that are
not shared by all the entities in the entity set.
o The E-R model provides a means for representing these distinctive entity
groupings. As an example, the entity set person may be further classified as one
of the following:
▪ employee
▪ student
o Each of these person types is described by a set of attributes that includes all
the attributes of entity set person plus possibly additional attributes.
o For example, employee entities may be described further by the attribute
salary, whereas student entities may be described further by the attribute
tot_credits.
o The process of designating subgroupings within an entity set is called
specialization.
Page 11
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
Page 12
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
Page 13
CS 4002 Unit 2- Data Modelling using ER Model (Part b)
o For example:
▪ Center entity offers the Course entity act as a single entity in the
relationship which is in a relationship with another entity visitor.
▪ In the real world, if a visitor visits a coaching center then he will never
enquiry about the Course only or just about the Center instead he will ask
the enquiry about both (the Center and the Course).
Page 14