1. RELATIONSHIP
IN DBMS
ADARSHA DALABEHERA-220301120183
RUDRA PRASAD BARAL-220301120187
G. SIPRARANI PATRA-220301120188
ABHIPSA SAHOO-220301120189
NYAYABRATA DAS -220301120191
2. CONTENTS:-
Introduction
How are relationships established ?
keys
Why are relationships important in a Database ?
Relationship
Types of relationship
Importance of relationship in DBMS
Conclusion
3. INTRODUCTION:-
A relationship in DBMS is the way in which two or
more data sets are linked i.e, any association between
two entity types is called a relationship.
The main feature of relational database is relationships.
Different relationship types control how the data and
tables relate to one another.
Establishing relationship makes this database type
unique, and knowing how relationship works helps
broaden database modeling capabilities.
4. How are relationships established ?
The two following elements define how a database
relationship is established.
Primary key
Foreign key
5. KEYS :-
Keys play an important role in the relational database.
It is used to uniquely identify any record or row of data from the table.
It is also used to establish and identify relationships between tables.
6. PRIMARY KEY:-
It is the first key used to identify one and only one instance of an entity uniquely. An
entity can contain multiple keys, as we saw in the PERSON table. The key which is
most suitable from those lists becomes a primary key.
In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License Number and Passport
Number as primary keys since they are also unique.
For each entity, the primary key selection is based on requirements and developers.
7. FOREIGN KEY:-
When tables relate , the primary key of one table becomes a foreign key of the
other table.
For the example, in the two tables on the right , employees table as a primary
key and in the order as a foreign key .
FOREIGN KEY when tables are linked by the primary key, the related field in
the second table is known as the foreign key.
8. CANDIDATE KEY:-
A candidate key is an attribute or set of attributes that can uniquely
identify a tuple(A tuple in DBMS is a collection of attribute values in
which no two unique items have the same name.).
Except for the primary key, the remaining attributes are considered a
candidate key.
The candidate keys are as strong as the primary key.
9. Example:-
• In the EMPLOYEE table, id is best suited for the primary key. The rest of the
attributes, like SSN, Passport_Number, License_Number, etc., are considered a
candidate key.
Candidate key
10. SUPER KEYS :
• Super key is an attribute set that can uniquely identify a tuple. A super
key is a superset of a candidate key.
• For example: In the EMPLOYEE table, for(EMPLOEE_ID,
EMPLOYEE_NAME), the name of two employees can be the same,
but their EMPLYEE_ID can't be the same. Hence, this combination
can also be a key.
11. ALTERNATE KEY:-
Alternate Key or Secondary Key is the key that has not been selected to be
the primary key, but are candidate keys.
However, it is considered a candidate key for the primary key.
For example, employee relation has two attributes, Employee_Id and
PAN_No, that act as candidate keys. In this relation, Employee_Id is
chosen as the primary key, so the other candidate key, PAN_No, acts as
the Alternate key.
12. COMPOSITE KEY:-
Whenever a primary key consists of more than one attribute, it is known
as a composite key. This key is also known as Concatenated Key.
For example, in employee relations, we assume that an employee may
be assigned multiple roles, and an employee may work on multiple
projects simultaneously. So the primary key will be composed of all three
attributes, namely Emp_ID, Emp_role, and Proj_ID in combination. So
these attributes act as a composite key since the primary key comprises
more than one attribute.
13. ARTIFICIAL KEY:-
The key created using arbitrarily assigned data are known as artificial keys.
These keys are created when a primary key is large and complex and has no
relationship with many other relations.
The data values of the artificial keys are usually numbered in a serial order.
For example, the primary key, which is composed of Emp_ID, Emp_role,
and Proj_ID, is large in employee relations. So it would be better to add a new
virtual attribute to identify each tuple in the relation uniquely.
14. Why are relationships important
in a Database ?
Relationships in a database help create meaningful information. As
a result, database relationships result in:
Reduced data redundancy : Relationships help reference
information stored in existing tables, reducing repetition.
Better organized database : Relationships help implement
database normalization techniques. Normalization helps yield a
better organized and robust database.
Referential integrity : As database grow, joins quires and sorting become
expensive. Relationships help reduce the number of transactions and improve
data validity.
15. RELATIONSHIP:-
DBMS, or Database Management Systems, is the process through which a Database
is managed or controlled.
A database is a collection of data. It may be in the form of tables, columns, charts,
texts, etc.
The way these databases are acted upon gives us , we call Database management
systems or DBMS.
The different steps that are taken to retrieve the data as well as store it, keeping in
mind strict security concerns, is the ideal definition of a DBMS.
16. CONTINUED:-
The different steps that are taken to retrieve the data as well as store
it, keeping in mind strict security concerns, is the ideal definition of a
DBMS.
A relationship is used to describe the relation between entities.
Diamond or rhombus is used to represent the relationship.
17. TYPES OF RELATIONSHIPS IN DBMS:-
There are four types of relationships that can be
found in DBMS:-
One to One
One to Many
Many to one
Many to Many
18. ONE-TO-ONE RELATIONSHIP:-
When only one instance of an entity is associated
with the relationship, then it is known as one-to-
one relationship.
For example, A female can marry to one
male, and a male can marry to one
female.
19. CONTINUED :-
In a one-to-one relationship, one record in a tables is associated with one and
only one record in another table. For example, in a school database, each
student has only one student ID, and each student ID is assigned to only one
person.
A one-to-one relationship looks like this in the relationships graph.
20. CONTINUED :-
In this example, the key field in each table, Student ID, is designed to
contain unique values. In the students table, the student ID field is the
Primary key; in the contact info table, the student ID field is a Foreign
key.
This relationship returns related records when the value in the Student
ID field in the Contact Info table is the same as the Student ID field in
the Students table.
21. ONE-TO-MANY RELATIONSHIP:-
When only one instance of the entity on the left, and more than one instance of an
entity on the right associates with the relationship then this is known as a one-to-
many relationship.
For example, Scientist can invent many inventions, but the invention is done by
the only specific scientist.
22. CONTINUED :-
To support a one-to-many relationship, we need to design
two tables.
We can then create the one-to-many relationship by storing
the primary key of the table Teacher (i.e., teacherID) (the
"one"-end or the parent table) in the table classes (the
"many"-end or the child table), as illustrated below.
The column teacherID in the child table Classes is known
as the foreign key. A foreign key of a child table is a
primary key of a parent table, used to reference the parent
table.
23. MANY-TO-ONE RELATIONSHIP:-
When more than one instance of the entity on the left, and only one
instance of an entity on the right associates with the relationship then it
is known as a many-to-one relationship.
For example, Student enrolls for only one course, but a course can have
many students.
24. In relational databases, many-to-one relationships are often enforced by
foreign key/primary key relationships, and the relationships typically are
between fact and dimension tables and between levels in a hierarchy.
The relationship is often used to describe classifications or groupings.
25. MANY-TO-MANY RELATIONSHIP:-
When more than one instance of the entity on the left, and more than
one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.
For example, Employee can assign by many projects and project can
have many employees.
26. CONTINUED :-
In this table where each row represent an item
of a particular order. For orderdetails table the
primary key consists of two columns : orderID
and productID, that uniquely identifies each
row.
The many-to-many relationship is, in fact,
implemented as two one-to-many relationships,
with the introduction of the junction table.
An order has many items in OrderDetails. An
OrderDetails item belongs to one particular
order.
A product may appear in many OrderDetails.
Each OrderDetails item specified one product.
27. CONTINUED:-
An order has many items in OrderDetails. An OrderDetails item belongs to one
particular order.
A product may appear in many OrderDetails. Each OrderDetails item specified one
product.
28. CONCLUSION:-
The relationship in a Database Management System (DBMS)
is the most essential part of its functioning. Without proper
relationships, the entire database structure would become
useless. We also need to keep in mind that though it is
essential to create relationships that may look to be complex
at times, it has to be thought after and well-defined for a
favorable outcome.