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

CS 4002 Unit - 2 Data Modelling Using ER Model (Part - B)

This document discusses key concepts in data modeling using entity-relationship (ER) modeling, including: 1. Mapping cardinalities (one-to-one, one-to-many, many-to-one, many-to-many) between entity sets in a relationship. 2. Key types such as super keys, candidate keys, alternate keys, primary keys, and composite keys and their roles in uniquely identifying entities. 3. Distinguishing between strong and weak entity sets and their relationships. 4. Extended ER features like specialization, generalization, attribute inheritance, and aggregation.

Uploaded by

ankur.cse23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

CS 4002 Unit - 2 Data Modelling Using ER Model (Part - B)

This document discusses key concepts in data modeling using entity-relationship (ER) modeling, including: 1. Mapping cardinalities (one-to-one, one-to-many, many-to-one, many-to-many) between entity sets in a relationship. 2. Key types such as super keys, candidate keys, alternate keys, primary keys, and composite keys and their roles in uniquely identifying entities. 3. Distinguishing between strong and weak entity sets and their relationships. 4. Extended ER features like specialization, generalization, attribute inheritance, and aggregation.

Uploaded by

ankur.cse23
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

CS 4002

Unit 2 – Part b

Ankur Verma 3/29/22 Data Modelling using ER Model


CS 4002 Unit 2- Data Modelling using ER Model (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.

• Many -to- One


An entity in A is associated with at most one entity in B.
An entity in B, however, can be associated with any
number (zero or more) of entities in A.

Page 2
CS 4002 Unit 2- Data Modelling using ER Model (Part b)

• Many -to- Many


An entity in A is associated with any number (zero or
more) of entities in B, and an entity in B is associated with
any number (zero or more) of entities in A.

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:

▪ Emp_SSN: The SSN number is stored in this field.


▪ Emp_Id: An attribute that stores the value of the employee identification
number.
▪ Emp_name: An attribute that stores the name of the employee holding the
specified employee id.

Page 3
CS 4002 Unit 2- Data Modelling using ER Model (Part b)

▪ Emp_email: An attribute that stores the email id of the specified


employees.

• 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)

▪ Emp_SSN: The SSN number of employees is stored in this field.


▪ Emp_Id: An attribute that stores the value of the employee identification
number.
▪ Emp_name: An attribute that stores the name of the employee holding the
specified employee id.
▪ Emp_email: An attribute that stores the email id of the specified
employees.
▪ So from the above table, there are the following Candidate keys:

• 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)

▪ Stud_roll_no: An attribute for providing an identification number to the


students.
▪ Stud_name: An attribute for storing the names of the students on the
specified roll numbers.
▪ Stud_email: An attribute that will hold the email id of the particular
student on a specified roll number.
▪ From the table, we can conclude that the roll number of the students can be
the most appropriate option for setting a Primary Key.
▪ Thus, Stud_roll_no is the primary key and the remaining identified keys
will be the candidate keys, hence the alternate keys.
• Primary Key
o There are certain keys in DBMS that are used for different purposes, from which
the most known is the Primary Key.
o What is Primary Key?
▪ A Primary Key is the minimal set of attributes of a table that has the task to
uniquely identify the rows, or we can say the tuples of the given particular
table.
▪ A primary key of a relation is one of the possible candidate keys which the
database designer thinks it's primary.
▪ It may be selected for convenience, performance, and many other reasons.
▪ The choice of the possible primary key from the candidate keys depend
upon the following condition:-
➢ Minimal: The primary key should be composed of the minimum
number of attributes that satisfy unique occurrences of the tuples.
So if one candidate key is formed using two attributes and another
using a single attribute then the one with the single attribute key should
be chosen as the primary key.
➢ Accessible: The primary key used should be accessible by anyone who
wants to use it. The user must easily insert, access, or delete a tuple
using it.

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)

▪ Cust_Id: A customer id is provided to each customer who visits and is


stored in this field.
▪ Order_Id: Each order placed by the customer is given an order id, which
is stored in this field.
▪ Prod_code: It holds the code value for the products available.
▪ Prod_name: An attribute holding the name of the product on the specified
product code.
▪ From the table, we found that no attribute is available that alone can
identify a record in the table and can become a primary key.
▪ However, the combination of some attributes can form a key and can
identify a tuple in the table.
▪ In the above example, Cust_Id and Prod_code can together form a
primary key because they alone are not able to identify a tuple, but together
they can do so.
• Foreign Key
o A foreign key is different from a super key, candidate key or primary key
because a foreign key is the one that is used to link two tables together or create
connectivity between the two.
o Here, in this section, we will discuss foreign key, its use and look at some
examples that will help us to understand the working and use of the foreign key.
o What is Foreign Key ?
▪ A foreign key is the one that is used to link two tables together via the
primary key.
▪ It means the columns of one table points to the primary key attribute of the
other table.
▪ It further means that if any attribute is set as a primary key attribute will
work in another table as a foreign key attribute.
▪ But one should know that a foreign key has nothing to do with the primary
key.
o Use of Foreign Key:-
▪ The use of a foreign key is simply to link the attributes of two tables
together with the help of a primary key attribute.
Page 8
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)

3) Strong and Weak Entity Sets


• Strong Entity Set
o A strong entity is not dependent on any other entity in the schema.
o A strong entity will always have a primary key.
o Strong entities are represented by a single rectangle.

o The relationship of two strong entities is represented by a single diamond.


o Various strong entities, when combined together, create a strong entity set.

• Weak Entity Set


o A weak entity is dependent on a strong entity to ensure its existence.
o Unlike a strong entity, a weak entity does not have any primary key.
o It instead has a partial discriminator key.
o A weak entity is represented by a double rectangle.

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

S.NO Strong Entity Weak Entity


1. Strong entity always has a primary While a weak entity has a partial
key. discriminator key.
2. Strong entity is not dependent on Weak entity depends on strong entity.
any other entity.
3. Strong entity is represented by a Weak entity is represented by a double
single rectangle. rectangle.
4. Two strong entity’s relationship is While the relation between one strong
Page 10
CS 4002 Unit 2- Data Modelling using ER Model (Part b)

represented by a single diamond. and one weak entity is represented by a


double diamond.
5. Strong entities have either total While weak entity always has total
participation or not. participation.

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)

o The specialization of person allows us to distinguish among person entities


according to whether they correspond to employees or students: in general, a
person could be an employee, a student, both, or neither.
• Generalization
o The design process may also proceed in a bottom-up manner, in which multiple
entity sets are synthesized into a higher-level entity set on the basis of common
features.
o The database designer may have first identified:
▪ instructor entity set with attributes instructor id, instructor
name, instructor salary, and rank.
▪ secretary entity set with attributes secretary id, secretary name,
secretary salary, and hours per week.
o There are similarities between the instructor entity set and the secretary
entity set in the sense that they have several attributes that are conceptually the
same across the two entity sets: namely, the identifier, name, and salary
attributes.
o This commonality can be expressed by generalization, which is a containment
relationship that exists between a higher-level entity set and one or more lower-
level entity sets.
o In our example, employee is the higher-level entity set and instructor and
secretary are lower-level entity sets.
o In this case, attributes that are conceptually the same had different names in the
two lower-level entity sets.
o To create a generalization, the attributes must be given a common name and
represented with the higher-level entity person.
o Higher- and lower-level entity sets also may be designated by the terms
superclass and subclass, respectively.
o The person entity set is the superclass of the employee and student subclasses.
o For all practical purposes, generalization is a simple inversion of specialization.
o We apply both processes, in combination, in the course of designing the E-R
schema for an enterprise.

Page 12
CS 4002 Unit 2- Data Modelling using ER Model (Part b)

o In terms of the E-R diagram itself, we do not distinguish between specialization


and generalization.
• Attribute Inheritance
o A crucial property of the higher- and lower-level entities created by
specialization and generalization is attribute inheritance.
o The attributes of the higher-level entity sets are said to be inherited by the lower-
level entity sets.
o For example, student and employee inherit the attributes of person.
o Thus, student is described by its ID, name, street, and city attributes, and
additionally a tot cred attribute; employee is described by its ID, name, street,
and city attributes, and additionally a salary attribute.
o Attribute inheritance applies through all tiers of lower-level entity sets; thus,
instructor and secretary, which are subclasses of employee, inherit the attributes
ID, name, street, and city from person, in addition to inheriting salary from
employee.
o Whether a given portion of an E-R model was arrived at by specialization or
generalization, the outcome is basically the same:
▪ A higher-level entity set with attributes and relationships that apply to all
of its lower-level entity sets.
▪ Lower-level entity sets with distinctive features that apply only within a
particular lower-level entity set.
• Aggregation
o One limitation of the E-R model is that it cannot express relationships among
relationships.
o In aggregation, the relation between two entities is treated as a single entity.
o In aggregation, relationship with its corresponding entities is aggregated into a
higher-level entity.

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

You might also like