Module 2
Module 2
important for designing the logical structure of databases. It helps define data and the relationship between the data
entities, and it makes the system easier to visualize.
ER Model is commonly used to design the structure of relational databases.
Makes it easy to construct and visualize data hierarchies.
Provides a clear framework for organizing database components.
Example :
The collection of all the students from the student table.
The collection of all the employees from the employee table.
Relation With Table :
Table Name : Student
1 John 19 M
2 Robert 23 M
3 Michael 21 M
4 Anna 16 F
Any particular row (a record) in a The name of a relation (table) in All rows of a relation (table)
relation (table) is known as an entity. RDBMS is an entity type in RDBMS is entity set
Entity Entity Type Entity Set
It is identified uniquely through a key It represents the structure of the It can grow or shrink as entities
attribute. table without data. are added or removed.
Simple Attribute
2. Composite Attribute
An attribute that can be split into components is a composite attribute.
Example: The address can be further split into house number, street number, city, state, country, and pin code, the
name can also be split into first name middle name, and last name.
Composite Attribute
3. Single-Valued Attribute
The attribute which takes up only a single value for each entity instance is a single-valued attribute.
Example: The age of a student, Aadhar card number.
Single-Valued
4. Multi-Valued Attribute
The attribute which takes up more than a single value for each entity instance is a multi-valued attribute. And it is
represented by double oval shape.
Example: Phone number of a student: Landline and mobile.
Multi-valued
5. Stored Attribute
The stored attribute are those attribute which doesn't require any type of further update since they are stored in
the database.
Example: DOB(Date of birth) is the stored attribute.
Stored-attribute
6. Derived Attribute
An attribute that can be derived from other attributes is derived attributes. And it is represented by dotted oval
shape.
Example: Total and average marks of a student, age of an employee that is derived from date of birth.
Derived-attribute
7. Complex Attribute
Those attributes, which can be formed by the nesting of composite and multi-valued attributes, are called "Complex
Attributes". These attributes are rarely used in DBMS(DataBase Management System). That's why they are not so
popular.
Example: Address because address contain composite value like street, city, state, PIN code and also multivalued
because one people has more that one house address.
Complex-attribute
What is Relationship Set in DBMS?
Relationship set in a Database Management System (DBMS) is essential as it provides the ability to store, recover,
and oversee endless sums of information effectively in cutting-edge data administration, hence making a difference
in organizations.
In a Relational database, relationship sets are built up by utilizing keys, such as primary and foreign keys, to interface
related records over distinctive tables.
What is a Relation?
A Relation in a database management system (DBMS) organizes information into rows and columns. This organized
arrangement makes a difference in information storing and recovering information proficiently. Relations permit us
to query information utilizing SQL commands like SELECT, Update, Insert, and Delete. Henceforth, it becomes easier
and more demanding to control and extract data from the database.
Relations are alluded to as tables within the database management system.
What is a Relationship Set?
It is a set of Relationships of the Same type. Mathematical Relation on m > 2 (Possibly non-distinct) entity Sets.
If E1, E2,...... En are the entity sets for the Relationship Set R is a subset of {(e1, e2,... en) | e1 € E1, e2 € E2....en € En}
Where (e1, e2,...en) is a Relationship.
For Example, (E-R Diagram)
Relationship Set
Characteristics of Relationship Set
Degree: Degree of a relationship set indicates to the number of properties related with the relationship set.
Arity: Arity of a relationship set indicates the number of taking part relations. It can be like double (including
two relations), ternary (including three relations), and so on.
Cardinality: Cardinality characterizes the number of occurrences or records that can be related with each
substance on both sides of the relationship.
This permits for the execution of different sorts of connections, such as one-to-one, one-to-many, and many-to-
many, reflecting real-world associations between substances.
Degree of Relationship Set
It denotes the number of entity sets that belong to that particular relationship set is called the degree of that
relationship set.
Degree of a Relationship Set = the number of entity set that belongs to that particular relationship set
Relationship Set Example With Tables
Let 'Customer' and 'Loan' entity sets defines the Relationship 'set Borrow' to denote the association between
Customer and bank loans.
one to one
2. Teacher-Student Relationship
Consider two relations: Teacher and Student. The relationship set between them can be characterized as “mentors.”
Each teacher mentors in one class, but a class can have numerous students. So one teacher can have many students.
This is often an illustration of a one-to-many relationship.
one to many
3. Student-Course Relationship
In this situation, we have two relations: Understudy and Course. The relationship set between them can be
characterized as “enrolled_in.” Each understudy can be selected in numerous courses, and each course can have
different understudies.
This can be an illustration of a many-to-many relationship.
many to many
In the Entity-Relationship (ER) model, relationships represent how two or more entities interact with each other.
These relationships are often depicted as a diamond-shaped box connecting the related entities. For instance, a
customer buying products is a common business relationship where the customer and the product are two entities,
and the act of buying forms the relationship.
Each relationship can have attributes, such as a timestamp recording when a customer buys a product. Thus,
relationships can have their own unique characteristics that further define the interaction between entities.
Example:
'Buys' is a relationship between customer entity and products. This relationship can be read as 'A customer buys a
product/products.
When a customer buys a product, there is a timestamp associated with it, so the attribute "Time" will be an
attribute of 'Buys'.
All the database concepts can be easily understood from the concepts of sets and relations.
By interpreting this, we can understand that many customers can buy the same type of product and many products
can be bought by many customers. And there are some products which are not bought by any customer and there
are some customers who do not buy any product.
Many
to many Relationship
As the relationship is many to many (M: N) between customer and product, therefore we require separate tables/
relations for 'buys'.
In buys relation, Cust_id and Prod_id are the foreign key to the customer and product.
Mapping cardinality is the maximum number of relationship instances in which an entity can participate.
Example:
Mathematically, here (e1, e2,e3...) are instances of an entity set Employee and (d1,d2, d3 ....) are the instances of
entity type department and (r1, r2, r3 ...) are relationship instances of relationship type.
Each instance ri(where i = 1,2,3,....) in R, is an association of entities, and the association includes exactly one entity
from each participating entity type. Each such relationship instance, ri represents that the entities participating in ri
are related in some way by any constraint/condition provided by the user to a designer.
In works_for binary relationship type Department: Employee is of cardinality (N:1), this means each
department can be related to any number of employees but an employee can be related to (works for) only
one department.
The possible cardinality ratios of binary relationship types are (1:1, 1:N, N:1, N:M).
All possible cardinality ratios for binary relationships are explained below with an example.
It is represented using an arrow(⇢,⇠)(There can be many notations possible for the ER diagram).
Example:
One
to One relationship
In this ER diagram, both entities customer and driving license having an arrow which means the entity Customer is
participating in the relation "has a" in a one-to-one fashion. It could be read as 'Each customer has exactly one
driving license and every driving license is associated with exactly one customer.
There may be customers who do not have a credit card, but every credit card is associated with exactly one
customer. Therefore, the entity customer has total participation in a relation.
Example:
one
to many relationship
This relationship is one to many because "There are some employees who manage more than one team while there
is only one manager to manage a team".
The set-theoretic perspective of the ER diagram is:
ER diagram
Many items from one group are connected to just one item in another group.
Example:
Many
to one relationship
This is a one-to-many relationship, but the difference comes from who must participate .The set-theoretic
perspective of the ER diagram is:
A customer can have many credit cards, but some customers might not have any. So, customer
participation is partial.
Every credit card must be linked to one customer. So, credit card participation is total.
Also, a credit card belongs to only one customer — it cannot be shared by multiple customers.
ER diagram
One entity in the first set can be related to many entities in the second set,
and One entity in the second set can also be related to many entities in the first set.
Example:
A customer can buy any number of products and a product can be bought by many customers.
Many
to many Relationship
ER diagram
Any of the four cardinalities of a binary relationship can have both sides partial, both total, and one partial, and one
total participation, depending on the constraints specified by user requirements.
Relationship Table
One-to-One 1 1 person<->passport
STUDENT Table
Table: STUDENT_COURSE
STUDENT_COURSE Table
A composite candidate key example: {STUD_NO, COURSE_NO} can be a candidate key for a STUDENT_COURSE table.
2. Super Key
The set of one or more attributes (columns) that can uniquely identify a tuple (record) is known as Super Key. It may
include extra attributes that aren't important for uniqueness but still uniquely identify the row. For Example,
STUD_NO, (STUD_NO, STUD_NAME), etc.
A super key can contain extra attributes that aren’t necessary for uniqueness and supports NULL values in
rows.
For example, if the "STUD_NO" column can uniquely identify a student, adding "SNAME" to it will still form a
valid super key, though it's unnecessary.
Example: Consider the STUDENT table
STUDENT Table
A super key could be a combination of STUD_NO and PHONE, as this combination uniquely identifies a student.
6. Primary Key
A primary key is chosen from the set of candidate keys to uniquely identify each record in a table. For example, in
the STUDENT table, both STUD_NO and STUD_PHONE can be candidate keys, but STUD_NO is selected as the
primary key.
It cannot be NULL, as each record must have a valid identifier.
It may be single-column or composite (made of multiple columns).
Databases often organize data using the primary key to allow faster access and searching.
Example: The STUDENT table has the structure Student(STUD_NO, SNAME, ADDRESS, PHONE), where STUD_NO is
the primary key.
7. Secondary Key
A Secondary Key is an attribute or a combination of attributes used to search or query records in a table, but it
doesn’t guarantee uniqueness.
It helps in retrieving data quickly, often by creating indexes.
It doesn’t uniquely identify each record; multiple records can have the same value.
For example, STUD_NAME in a STUDENT table can be used to find students by name, even though many
students may share the same name.
It’s mainly for improving search efficiency, not for maintaining data uniqueness.
Here's an example of how the STUDENT table might look with STUD_NAME as a secondary key:
STUD_NO STUD_NAME STUD_AGE STUD_ADDRESS
8. Unique Key
A Unique Key is a database constraint that ensures that all values in a specific column or a combination of columns
are unique across all the rows in a table. It guarantees that no two rows in the table can have the same value in the
columns defined as part of the unique key.
Prevents duplicate values in the specified column(s).
It allows NULL values, but only one NULL per column.
It can be applied to a single column or multiple columns.
Helps maintain the integrity and accuracy of the data in the table.
Example: In the STUDENT_COURSE table, the combination of STUD_EMAIL and STUD_NAME can form a Unique Key
to ensure that each student’s email and name pair is unique across the table.
9. Composite Key
Sometimes, a single column is not enough to uniquely identify all records in a table, so a combination of multiple
attributes is used. An optimal set of such attributes is chosen to ensure that every row is uniquely identifiable.
It acts as a primary key if there is no primary key in a table
Two or more attributes are used together to make a composite key .
Different combinations of attributes may give different accuracy in terms of identifying the rows uniquely.
Example: In the STUDENT_COURSE table, {STUD_NO, COURSE_NO} can form a composite key to uniquely identify
each record.
10. Surrogate Keys
A surrogate key is an artificial attribute created to uniquely identify each record in a table when no suitable natural
key is available.
It is usually generated automatically by the system (like auto-increment numbers).
It acts as a primary key when natural or composite keys are not practical or efficient.
A single system-generated attribute is used to make a surrogate key.
It does not have any real-world meaning and is used only for identification purposes.
Example: STUDENT_ID is used as a surrogate key to uniquely identify each record in the STUDENT_COURSE table,
without relying on natural attributes like name or email.
In DBMS, the degree of a relationship refers to the number of entity types involved in that relationship. For instance,
if a Student entity is connected to a Bag entity through a primary key–foreign key relationship, the interaction
between these two entities represents a relationship of degree two.
Unary (Degree 1)
In this type of relationship, both the associating entity types are the same. So, we can say that unary relationships
exist when both entity types are the same and we call them the degree of relationship is 1. In other words, in a
relation only one entity set is participating then such type of relationship is known as a unary relationship.
Example: In a particular class, we have many students, there are monitors too. So, here class monitors are also
students. Thus, we can say that only students are participating here. So the degree of such type of relationship is 1.
Unary
Binary (Degree 2)
In a Binary relationship, there are two types of entity associates. So, we can say that a Binary relationship exists
when there are two types of entity. Or in other words, in a relation when two entity sets are participating then such
type of relationship is known as a binary relationship. This is the most used relationship and one can easily be
converted into a relational table.
Example: We have two entity types 'Student' and 'ID' where each ‘Student’ has his 'ID'. So, here two entity types are
associating we can say it is a binary relationship. Also, one ‘Father’ can have many ‘daughters’ but each ‘daughter’
should belong to only one ‘father. We can say that it is a one-to-many binary relationship.
Binary
Ternary (Degree 3)
In the Ternary relationship, there are three types of entity associates. So, we can say that a Ternary relationship
exists when there are three types of entity and we call them a degree of relationship is 3. Since the number of
entities increases due to this, it becomes very complex to turn E-R into a relational table. Now let's understand with
the examples.
Example: We have three entity types ‘Teacher’, ‘Course’, and ‘Class’. The relationship between these entities is
defined as the teacher teaching a particular course, also the teacher teaches a particular class. So, here three entity
types are associating we can say it is a ternary relationship.
Ternary
N-ary (n Degree)
In the N-ary relationship, there are n types of entity that associates. So, we can say that an N-ary relationship exists
when there are n types of entities. There is one limitation of the N-ary relationship, as there are many entities so it is
very hard to convert into an entity, rational table. So, this is very uncommon, unlike binary which is very much
popular.
Example: We have 5 entities Teacher, Class, Location, Salary, Course. So, here five entity types are associating we
can say an n-ary relationship is 5.
N-ary
Introduction of ER Model
Uses of ER Diagrams in DBMS
ER diagrams represent the E-R model in a database, making them easy to convert into relations (tables).
These diagrams serve the purpose of real-world modeling of objects which makes them intently useful.
Unlike technical schemas, ER diagrams require no technical knowledge of the underlying DBMS used.
They visually model data and its relationships, making complex systems easier to understand.
ER Model is used to model the logical view of the system from a data perspective which consists of these symbols:
Types of Entity
1. Strong Entity
A type of entity that has a key Attribute that can uniquely identify each instance of the entity. A Strong Entity does
not depend on any other Entity in the Schema for its identification. It has a primary key that ensures its uniqueness
and is represented by a rectangle in an ER diagram.
2. Weak Entity
It cannot be uniquely identified by its own attributes alone. It depends on a strong entity to be identified. A weak
entity is associated with an identifying entity (strong entity), which helps in its identification. A weak entity are
represented by a double rectangle. The participation of weak entity types is always total. The relationship between
the weak entity type and its identifying strong entity type is called identifying relationship and it is represented by a
double diamond.
Example:
A company may store the information of dependents (Parents, Children, Spouse) of an Employee. But the
dependents can't exist without the employee. So dependent will be a Weak Entity Type and Employee will be
identifying entity type for dependent, which means it is Strong Entity Type.
A superclass shows a broad category of entities, however its subclasses define more specific groupings within that
category. The superclass-subclass relationship helps us model hierarchical data.
For example, consider the EMPLOYEE entity type in a company’s database. It is a broad category that might include
subclasses such as:
SECRETARY − Employees who handle administrative tasks.
TECHNICIAN − Employees who provide technical support or services.
ENGINEER − Employees who design and develop systems or products.
The EMPLOYEE entity type is like the superclass, it has the shared characteristics of all employees. The specific roles
like ENGINEER or SECRETARY are the subclasses.
The Class / Subclass Relationship
The connection between a superclass and its subclasses is known as the class-subclass relationship. This relationship
shows that entities in a subclass are also members of the superclass.
For example, a TECHNICIAN entity is an EMPLOYEE with additional characteristics specific to the TECHNICIAN role.
Similarly, a SECRETARY is an EMPLOYEE but with unique attributes, such as Typing_speed. This relationship is often
described using an "is-a" relationship:
A TECHNICIAN is an
A SECRETARY is an
Generalization
Example: STUDENT and FACULTY can be generalized to a higher-level entity called PERSON as shown in diagram
below. In this case, common attributes like P_NAME and P_ADD become part of a higher entity (PERSON) and
specialized attributes like S_FEE become part of a specialized entity (STUDENT).
Specialization
In specialization, an entity is divided into sub-entities based on its characteristics. It is a top-down approach where
the higher-level entity is specialized into two or more lower-level entities.
Specialization
Example: an EMPLOYEE entity in an Employee management system can be specialized into DEVELOPER, TESTER, etc.
In this case, common attributes like E_NAME, E_SAL, etc. become part of a higher entity (EMPLOYEE) and specialized
attributes like TES_TYPE become part of a specialized entity (TESTER).
Inheritance
It is an important feature of generalization and specialization. In specialization, a higher-level entity is divided into
lower-level sub-entities that inherit its attributes. In generalization, similar lower-level entities are combined into a
higher-level entity that holds common attributes. In both cases, inheritance allows sub-entities to reuse the
properties of the parent entity.
1. Attribute inheritance: It allows lower level entities to inherit the attributes of higher level entities but not
vice versa. In below diagram Car is a subclass of Vehicle and inherits its attributes.
2. Relationship Inheritance: Sub-entities also inherit relationships of the parent entity.
3. Overriding Inheritance: Sub-entities can override or add their own attributes or behaviors different from the
parent.
4. Participation inheritance: Participation inheritance in ER modeling refers to the inheritance of participation
constraints from a higher-level entity (superclass) to a lower-level entity (subclass). It ensures that subclasses
adhere to the same participation rules in relationships, although attributes and relationships themselves are
inherited differently.
Example of Relation
Example: In diagram Vehicle entity has an relationship with Cycle entity, but but it does not automatically inherit the
relationship itself with the Vehicle entity. Participation inheritance only refers to the inheritance of participation
constraints, not the actual relationships between entities.
Aggregation
An ER diagram is not capable of representing the 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 we can represent relationships as higher-level entity sets.
Example: an Employee working on a project may require some machinery. So, REQUIRE relationship is needed
between the relationship WORKS_FOR and entity MACHINERY. Using aggregation, WORKS_FOR relationship with its
entities EMPLOYEE and PROJECT is aggregated into a single entity and relationship REQUIRE is created between the
aggregated entity and MACHINERY.
Difference Between Strong and Weak Entity
Strong entity always has a primary key. While a weak entity has a partial discriminator key.
Two strong entity's relationship is represented While the relation between one strong and one weak entity is
by a single diamond. represented by a double diamond.
Unified Modeling Language (UML) is a type of general modeling language that is used to diagram, describe, build,
and document the static and dynamic structure of software systems. UML diagrams refer to tools that assist
developers and designers in designing structures and processes of constructing software by the use of symbols. Use
case diagrams, class diagrams, sequence diagrams, and activity diagrams, which are part of UML, all assist in
comprehending the movement of a system.
Advantages of UML
Comprehensive Software Representation: UML also permits the delineation of software structures and
behaviors of a certain system in a more refined manner in contrast to data flow diagrams.
Standardization: It uses standard notations that enhance how the different teams interact and share
information during the development phase of the software.
Flexibility: One of the main advantages of utilizing UML is the fact that it has the capability of being used in
both small-scale and large-scale systems and does not restrict its usage to certain technologies.
Extensive Diagram Types: UML is comprised of various diagrams, including class diagrams, sequence
diagrams, activity diagrams, and so on, which are designed to provide specific support to particular activities
in software development processes.
Disadvantages of UML
Complexity: However, for small projects, UML seems to complicate things and, if not well guided, may lead
to higher costs of development than necessary.
Steep Learning Curve: Each diagram in UML has been developed for a particular purpose, and it is important
to understand them all while using UML. This poses a challenge to persons new to system design or to those
non-technical stakeholders who want to understand UML simplified.
Time-Consuming: While creating the detailed UML diagrams, it is a very time-consuming process, especially
for the large systems consisting of many components and interactions.
Use It is used to design the entire software. It is used to design only the databases.
Components It has use cases and workflows. It has entities, attributes and relationships.
Use of
It uses swimlanes. It does not use swimlanes.
Swimlanes