Assignment
Assignment
Concepts
Tables − In relational data model, relations are saved in the format of Tables.
This format stores the relation among entities. A table has rows and columns,
where rows represents records and columns represent the attributes.
Tuple − A single row of a table, which contains a single record for that relation
is called a tuple.
Relation instance − A finite set of tuples in the relational database system
represents relation instance. Relation instances do not have duplicate tuples.
Relation schema − A relation schema describes the relation name (table
name), attributes, and their names.
Relation key − Each row has one or more attributes, known as relation key,
which can identify the row in the relation (table) uniquely.
Attribute domain − Every attribute has some pre-defined value scope, known
as attribute domain.
Constraints
Every relation has some conditions that must hold for it to be a valid relation.
These conditions are called Relational Integrity Constraints. There are
three main integrity constraints −
Key constraints
Domain constraints
Referential integrity constraints
Example of
Entity
Relationship
Diagram
representation of the above weak entity set:
What is
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.
A UML class diagram is a visual tool that represents the structure of
a system by showing its classes, attributes, methods, and the
relationships between them. It helps everyone involved in a project—
like developers and designers—understand how the system is
organized and how its components interact.
What are class Diagrams?
Class diagrams are a type of UML (Unified Modeling Language)
diagram used in software engineering to visually represent the
structure and relationships of classes within a system i.e. used to
construct and visualize object-oriented systems.
In these diagrams, classes are depicted as boxes, each containing
three compartments for the class name, attributes, and methods.
Lines connecting classes illustrate associations, showing relationships
such as one-to-one or one-to-many.
Class diagrams provide a high-level overview of a system’s design,
helping to communicate and document the structure of the software.
They are a fundamental tool in object-oriented design and play a
crucial role in the software development lifecycle.
If you want to enhance your skills in creating effective class
diagrams, the System Design Course offers step-by-step guidance
on mastering UML and class diagrams.
What is a class?
In object-oriented programming (OOP), a class is a blueprint or
template for creating objects. Objects are instances of classes, and
each class defines a set of attributes (data members) and methods
(functions or procedures) that the objects created from that class will
possess. The attributes represent the characteristics or properties of
the object, while the methods define the behaviors or actions that the
object can perform.
UML Class Notation
class notation is a graphical representation used to depict classes and
their relationships in object-oriented modeling.
1.Class Name:
package)
Parameter Directionality
In class diagrams, parameter directionality refers to the indication of
the flow of information between classes through method parameters.
It helps to specify whether a parameter is an input, an output, or both.
This information is crucial for understanding how data is passed
between objects during method calls.
2. Directed Association
A directed association in a UML class diagram represents a
relationship between two classes where the association has a
direction, indicating that one class is associated with another in a
specific way.
In a directed association, an arrowhead is added to the association
line to indicate the direction of the relationship. The arrow points from
the class that initiates the association to the class that is being
targeted or affected by the association.
Directed associations are used when the association has a specific
flow or directionality, such as indicating which class is responsible for
initiating the association or which class has a dependency on another.
Consider a scenario where a “Teacher” class is associated with a
“Course” class in a university system. The directed association arrow
may point from the “Teacher” class to the “Course” class, indicating
that a teacher is associated with or teaches a specific course.
The source class is the “Teacher” class. The “Teacher” class initiates
the association by teaching a specific course.
The target class is the “Course” class. The “Course” class is affected
by the association as it is being taught by a specific teacher.
3. Aggregation
Aggregation is a specialized form of association that represents a
“whole-part” relationship. It denotes a stronger relationship where one
class (the whole) contains or is composed of another class (the part).
Aggregation is represented by a diamond shape on the side of the
whole class. In this kind of relationship, the child class can exist
independently of its parent class.
Let’s understand aggregation using an example:
The company can be considered as the whole, while the employees
are the parts. Employees belong to the company, and the company
can have multiple employees. However, if the company ceases to
exist, the employees can still exist independently.
4. Composition
Composition is a stronger form of aggregation, indicating a more
significant ownership or dependency relationship. In composition, the
part class cannot exist independently of the whole class. Composition
is represented by a filled diamond shape on the side of the whole
class.
Let’s understand Composition using an example:
Imagine a digital contact book application. The contact book is the
whole, and each contact entry is a part. Each contact entry is fully
owned and managed by the contact book. If the contact book is
deleted or destroyed, all associated contact entries are also removed.
This illustrates composition because the existence of the contact
entries depends entirely on the presence of the contact book. Without
the contact book, the individual contact entries lose their meaning and
cannot exist on their own.
5. Generalization(Inheritance)
Inheritance represents an “is-a” relationship between classes, where
one class (the subclass or child) inherits the properties and behaviors
of another class (the superclass or parent). Inheritance is depicted by
a solid line with a closed, hollow arrowhead pointing from the subclass
to the superclass.
In the example of bank accounts, we can use generalization to
represent different types of accounts such as current accounts,
savings accounts, and credit accounts.
The Bank Account class serves as the generalized representation of all
types of bank accounts, while the subclasses (Current Account,
Savings Account, Credit Account) represent specialized versions that
inherit and extend the functionality of the base class.
Person class depends on the Book class to access and read the
content.
Book Class: Represents a book that contains content to be read by a
person. The Book class is independent and can exist without the
Person class.
The Person class depends on the Book class because it requires
access to a book to read its content. However, the Book class does not
depend on the Person class; it can exist independently and does not
rely on the Person class for its functionality.
8. Usage(Dependency) Relationship
A usage dependency relationship in a UML class diagram indicates
that one class (the client) utilizes or depends on another class (the
supplier) to perform certain tasks or access certain functionality. The
client class relies on the services provided by the supplier class but
does not own or create instances of it.
In UML class diagrams, usage dependencies are typically represented
by a dashed arrowed line pointing from the client class to the supplier
class.
The arrow indicates the direction of the dependency, showing that
the client class depends on the services provided by the supplier
class.
Consider a scenario where a “Car” class depends on a “FuelTank”
class to manage fuel consumption.
The “Car” class may need to access methods or attributes of the
“FuelTank” class to check the fuel level, refill fuel, or monitor fuel
consumption.
In this case, the “Car” class has a usage dependency on the
“FuelTank” class because it utilizes its services to perform certain
tasks related to fuel management.
What is inheritance
Generalization
Generalization is the process of extracting common properties from a
set of entities and creating a generalized entity from it. It is a bottom-
up approach in which two or more entities can be generalized to a
higher-level entity if they have some attributes in common. For
Example, STUDENT and FACULTY can be generalized to a higher-level
entity called PERSON as shown in Figure 1. 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).
Generalization is also called as ‘ Bottom-up approach”.
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. For Example, an
EMPLOYEE entity in an Employee management system can be
specialized into DEVELOPER, TESTER, etc. as shown in Figure 2. 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).
Specialization is also called as ” Top-Down approch”.
attributes of higher level entities and vice versa. In diagram Car entity
is an inheritance of Vehicle entity ,So Car can acquire attributes
of Vehicle. Example:car can acquire Model attribute of Vehicle.
Participation inheritance: Participation inheritance in ER modeling
Candidate Key
The minimal set of attributes that can uniquely identify a tuple is
known as a candidate key. For Example, STUD_NO in STUDENT
relation.
It is a minimal super key.
It is a super key with no repeated data is called a candidate key.
The minimal set of attributes that can uniquely identify a record.
It must contain unique values.
It can contain NULL values.
Every table must have at least a single candidate key.
A table can have multiple candidate keys but only one primary key.
The value of the Candidate Key is unique and may be null for a tuple.
There can be more than one candidate key in a relationship.
Example:
STUD_NO is the candidate key for relation STUDENT.
Table STUDENT
SNA ADDRE
STUD_NO PHONE
ME SS
1234567
1 Shyam Delhi
89
2233657
2 Rakesh Kolkata
96
1754689
3 Suraj Delhi
65
1 001 C001
2 056 C005
Primary Key
There can be more than one candidate key in relation out of which one
can be chosen as the primary key. For Example, STUD_NO, as well as
STUD_PHONE, are candidate keys for relation STUDENT but STUD_NO
can be chosen as the primary key (only one out of many candidate
keys).
It is a unique key.
It can identify only one tuple (a record) at a time.
It has no duplicate values, it has unique values.
It cannot be NULL.
Primary keys are not necessarily to be a single column; more than
one column can also be a primary key for a table.
Example:
STUDENT table -> Student(STUD_NO, SNAME,
ADDRESS, PHONE) , STUD_NO is a primary key
Table STUDENT
SNA ADDRE
STUD_NO PHONE
ME SS
1234567
1 Shyam Delhi
89
2233657
2 Rakesh Kolkata
96
1754689
3 Suraj Delhi
65
Super Key
The set of attributes that can uniquely identify a tuple is known as
Super Key. For Example, STUD_NO, (STUD_NO, STUD_NAME), etc. A
super key is a group of single or multiple keys that identifies rows in a
table. It supports NULL values.
Adding zero or more attributes to the candidate key generates the
super key.
A candidate key is a super key but vice versa is not true.
Super Key values may also be NULL.
Example:
Consider the table shown above.
STUD_NO+PHONE is a super key.
Alternate Key
The candidate key other than the primary key is called an alternate
key .
All the keys which are not primary keys are called alternate keys.
It is a secondary key.
It contains two or more fields to identify two or more records.
These values are repeated.
Eg:- SNAME, and ADDRESS is Alternate keys
Example:
Consider the table shown above.
STUD_NO, as well as PHONE both,
are candidate keys for relation STUDENT but
PHONE will be an alternate key
(only one out of many candidate keys).
Foreign Key
If an attribute can only take the values which are present as values of
some other attribute, it will be a foreign key to the attribute to which
it refers. The relation which is being referenced is called referenced
relation and the corresponding attribute is called referenced attribute.
The referenced attribute of the referenced relation should be the
primary key to it.
It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
It combines two or more relations (tables) at a time.
They act as a cross-reference between the tables.
For example, DNO is a primary key in the DEPT table and a non-key in
EMP
Example:
Refer Table STUDENT shown above.
STUD_NO in STUDENT_COURSE is a
foreign key to STUD_NO in STUDENT relation.
Table STUDENT_COURSE
TEACHER_N COURSE_N
STUD_NO
O O
1 005 C001
2 056 C005
It may be worth noting that, unlike the Primary Key of any given
relation, Foreign Key can be NULL as well as may contain duplicate
tuples i.e. it need not follow uniqueness constraint. For Example,
STUD_NO in the STUDENT_COURSE relation is not unique. It has been
repeated for the first and third tuples. However, the STUD_NO in
STUDENT relation is a primary key and it needs to be always unique,
and it cannot be null.
Composite Key
Sometimes, a table might not have a single column/attribute that
uniquely identifies all the records of a table. To uniquely identify rows
of a table, a combination of two or more columns/attributes can be
used. It still can give duplicate values in rare cases. So, we need to
find the optimal set of attributes that can uniquely identify rows in a
table.
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 .
Example
Let's take the student as an entity. Students will have multiple
attributes such as roll number, name, and class.
These attributes are used to describe the student in more detail.
Types Of Attribute
There are 8 types of attributes in DBMS.
Simple Attribute.
Composite Attribute.
Multivalued Attribute.
Key Attribute.
Derived Attribute.
Stored Attribute.
Complex Attribute.
of attributes.
Composite Attribute
When 2 or more than 2 simple attributes are combined to make an
Multivalued Attribute
An attribute which can have multiple values is known as
Multi-valued attributes are used when more than 1 entries for one
attribute need to be stored in the Database.
Key Attribute
The attribute which has unique values for every row in the table is
known as a Key Attribute. The key attribute has a very crucial role in
the database.
The key attribute is a distinct and unique characteristic of the entity
that can be used to identify the entity uniquely.
Example
For students, we can identify every student with roll_no because
Derived Attribute
The attribute that can be derived from the other attributes and does