0% found this document useful (0 votes)
6 views139 pages

Module No - 3 DBMS

This document covers the relational model and relational algebra, detailing the logical design of databases and the translation of conceptual schemas into relational schemas. It explains key concepts such as relations, attributes, tuples, domains, and various types of keys, including primary, foreign, and composite keys. Additionally, it discusses the mapping of ER and EER models to relational models, outlining steps for converting entity types and relationships into relational schemas suitable for implementation in RDBMS.

Uploaded by

litdumacc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views139 pages

Module No - 3 DBMS

This document covers the relational model and relational algebra, detailing the logical design of databases and the translation of conceptual schemas into relational schemas. It explains key concepts such as relations, attributes, tuples, domains, and various types of keys, including primary, foreign, and composite keys. Additionally, it discusses the mapping of ER and EER models to relational models, outlining steps for converting entity types and relationships into relational schemas suitable for implementation in RDBMS.

Uploaded by

litdumacc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 139

MODULE NO:-3

Relational Model and Relational


Algebra

Computer Engineering Department


Semester-IV
MODULE NO:-3 Relational Model and Relational Algebra :

3.1. Introduction to the Relational Model,


3.2. relational schema
3.3. concept of keys
3.4. Mapping the ER and EER Model to the
Relational Model
3.5. Relational Algebra –
unary and set operations,
Relational Algebra operations
Introduction to the Relational Model
➢ The logical design of a database consists in translating the conceptual
schema of the data into a logical schema.
➢ The logical model is independent of the physical model, i.e. the physical
representation of the data.
➢ The logical model that we will use is called relational model (RM).

The relational model consists of two main components:


•the structures that allow to organize the data;
•the integrity constraints that allow data to be kept consistent.
Introduction to the Relational Model
➢ Conceptual Design: The requirements of database are
captured using high level conceptual data model. For
Example, the ER model is used for the conceptual design
of the database.
➢ Logical Design: Logical Design represents data in the
form of relational model. ER diagram produced in the
conceptual design phase is used to convert the data into
the Relational Model.
➢ Physical Design: In physical design, data in relational
model is implemented using commercial DBMS like
Oracle, DB2.
Introduction to the Relational Model

➢ The Relational model of data is based on the concept of Relation.


➢ Relational Model (RM) represents the database as a collection of relations.
➢ A relation is nothing but a table of values.
➢ Every row in the table represents a collection of related data values.
➢ These rows in the table denote a real-world entity or relationship.
Introduction to the Relational Model
MODULE NO:-3 Relational Model and Relational Algebra :

3.1. Introduction to the Relational Model,


3.2. relational schema
3.3. concept of keys
3.4. Mapping the ER and EER Model to the
Relational Model
3.5. Relational Algebra –
unary and set operations,
Relational Algebra operations
Relational Schema Terms
Relational Model Concepts in DBMS

➢ Relation
➢ Attribute
➢ Tuple
➢ Domain
➢ Relational Schema
Relational Schema Terms
Relational Model Concepts in DBMS
1.Relation – In the Relational model the, relations are saved in the table format. It is stored
along with its entities. A table has two properties rows and columns. Rows represent
records/tuple and columns represent attributes.
Relational Schema Terms
Relational Model Concepts in DBMS
2.Attribute: Each column in a Table. Attributes are the properties which define a relation.
e.g., Student_Rollno, NAME,etc.
Relational Schema Terms
Relational Model Concepts in DBMS
3.Tuple – It is nothing but a single row of a table, which contains a single record.
Relational Schema Terms
Relational Model Concepts in DBMS
4.Domain– Every attribute has some pre-defined value and scope (data type) which is
known as attribute domain. It contains a set of atomic values that an attribute can take.
Relational Schema Terms
Relational Model Concepts in DBMS
5.Relation Schema: A relation schema represents the name of the relation with its attributes.
Relational Schema Terms
Relational Model Concepts in DBMS
5.Relation Schema: A relation schema represents the name of the relation with its attributes.
Relational Schema Terms
Relational Model Concepts in DBMS
4.Relation Schema: A relation schema represents the name of the relation with its attributes.
Relational Schema Terms
Relational Model Concepts in DBMS
5.Database Schema:
Relational Schema Terms
Relational Model Concepts in DBMS
6.Degree: The total number of attributes which in the relation is called the degree of the
relation.
7.Cardinality: Total number of rows present in the Table.
Relational Schema Terms
Relational Model Concepts in DBMS
Relational Schema Terms
Relational Model Concepts in DBMS
Relation instance – Relation instance is a finite set of tuples in the RDBMS system.
Relation instances never have duplicate tuples.
Relational Schema Terms
MODULE NO:-3 Relational Model and Relational Algebra :

3.1. Introduction to the Relational Model,


3.2. Relational schema
3.3. concept of keys
3.4. Mapping the ER and EER Model to the
Relational Model
3.5. Relational Algebra –
unary and set operations,
Relational Algebra operations
Concept of Keys

KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in
a relation(table).
They allow you to find the relation between two tables.
Keys help you uniquely identify a row in a table by a combination of one or more columns
in that table.
Relational Model has following keys
•Primary Key
•Foreign Key
•Candidate Key
•Alternate Key
•Super Key
Concept of Keys
Super Key
•A super key is a group of single or multiple keys which uniquely identifies rows in a table.
• A Super key may have additional attributes that are not needed for unique identification.
Example of the super key
Consider the student table with columns [ID,NAME,PHONE]
•[ID]: As no two students will have the same Id, it will help to uniquely access the student
details, hence it is a super keyNow we will identify all the Super Keys present in the table that is
the set of attributes that will help to uniquely access a record
•[NAME, ID]: Even if more than one student has the same name then the combination name
will help to recognize the record, as student id will break the tie and this is combination is a
super key
Concept of Keys
Super Key
Example of the super key
Consider the student table with columns
[ID,NAME,PHONE]
•[ID]: As no two students will have the same Id, it will
help to uniquely access the student details, hence it is a
super key .

• [NAME, ID]: Even if more than one student has the


same name then the combination name will help to
recognize the record, as student id will break the tie and
this is combination is a super key
Concept of Keys
Concept of Keys

Rules for defining Primary key:


•Two rows can't have the same primary key value
•It is madatory for every row to have a primary key value.
•The primary key field cannot be null.
•The value in a primary key column can never be modified or
updated if any foreign key refers to that primary key.
Concept of Keys
Concept of Keys
Alternate Key – Out of all candidate keys, only one gets selected as primary
key, remaining keys are known as alternate or secondary keys.
Concept of Keys

Composite Key – A key that consists of more than one attribute to uniquely
identify rows (also known as records & tuples) in a table is called composite key.
Concept of Keys
Foreign Key – Foreign keys are the columns of a table that points to the
primary key of another table. They act as a cross-reference between tables.
Employee table Department table

Primary key
Foreign key
Concept of Keys
32
MODULE NO:-3 Relational Model and Relational Algebra :

3.1. Introduction to the Relational Model,


3.2. Relational schema
3.3. concept of keys
3.4. Mapping the ER and EER Model to the
Relational Model
3.5. Relational Algebra –
unary and set operations,
Relational Algebra operations
Mapping of ER and EER to Relational Model
After designing the ER diagram of system, we need to convert it to Relational models
which can directly be implemented by any RDBMS like Oracle, MySQL etc.

1. Mapping of Regular Entity Types


2. Mapping of Weak Entity Types.
3. Mapping of Binary 1:1 Relationship Types
4. Mapping of Binary 1:N Relationship Types
5. Mapping of Binary M:N Relationship Types
6. Mapping of Multivalued Attributes.
7. Mapping of N-ary Relationship Types.
Mapping of ER and EER to Relational Model

Step 1: MAPPING STRONG ENTITIES


➢ For each regular entity type E •
➢ Create a relation R that includes all the simple attributes of E. •
➢ Include all the simple component attributes of composite attributes. •
➢ Choose one of the key attributes of E as primary key for R. •
➢ If the chosen key of E is composite, the set of simple attributes that form it
will together form the primary key of R.
Mapping of ER and EER to Relational Model
Mapping of ER and EER to Relational Model

Step 2: MAPPING WEAK ENTITY TYPE


➢ For each weak entity type W associated with owner/strong entity type E •

➢ Create a relation R, and include all simple attributes and simple


components of composite attributes of W as attributes of R. •

➢ In addition, include as foreign key attributes of R the primary key


attribute(s) of the relation(s) that correspond to the owner entity type(s)
Mapping of ER and EER to Relational Model
Mapping of ER and EER to Relational Model
Step 3: For each binary 1:1 relationship type R •
➢ Identify the relations S and T that correspond to the entity types participating in R.

➢ Choose one of the relations, say S, and include as foreign key in S the primary key of T.

➢ It is better to choose an entity type with total participation in R in the role of S. •

➢ Include the simple attributes of the 1:1 relationship type R as attributes of S. •

➢ If both participations are total, we may merge the two entity types and the relationship
into a single relation.
Mapping of ER and EER to Relational Model
Foreign key approach
Mapping of ER and EER to Relational Model Foreign key approach
Mapping of ER and EER to Relational Model Merge relation approach
When total participation both ways
Mapping of ER and EER to Relational Model Cross Reference approach
For each binary 1:1 relationship type R in the ER schema, identify the relations S and T that correspond to the
entity types participating in R.
Mapping of ER and EER to Relational Model

Step 4: For each regular binary 1:N relationship type R •


➢ Identify the relation S that represents the participating entity type at the N-side of the
relationship type. •
➢ Include as foreign key in S the primary key of the relations T that represents the other
entity type participating in R. •
➢ Include any simple attributes of the 1:N relationship type as attributes of S.
Mapping of ER and EER to Relational Model
Mapping of ER and EER to Relational Model

Step 5: For each binary M:N relationship type R •


➢ Create a new relation S to represent R. •

➢ Include as foreign key attributes in S the primary keys of the relations that
represent the participating entity types; their combination will form the primary
key of S.

➢ Also, include any simple attributes of the M:N relationship type as attributes of S.
Mapping of ER and EER to Relational Model
Mapping of ER and EER to Relational Model

Step 6: For each multi-valued attribute A •

➢ Create a new relation R that includes an attribute corresponding to A plus the


primary key attribute K (as a foreign key in R) of the relation that represents the
entity type or relationship type that has A as an attribute. •

➢ The primary key of R is the combination of A and K. If a multi-valued attribute is


composite, we include its components.
Mapping of ER and EER to Relational Model
Mapping of ER and EER to Relational Model
Step 7: For each n-ary relationship type R, n>2 •
➢ Create a new relation S to represent R. •

➢ Include as foreign key attributes in the S the primary keys of the relations that
represent the participating entity types. •

➢ Also include any simple attributes of the nary relationship types as attributes of S. •

➢ The primary key for S is usually a combination of all the foreign keys that reference
the relations representing the participating entity types.
Mapping of ER and EER to Relational Model
Mapping of EER to Relational Model
➢ EER model = ER Model + hierarchical relationships
Entities that are member of one entity type (the superclass) may be grouped into
meaningful subsets (the subclasses)
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.

Convert each specialization with m subclasses {S1, S2,….,Sm} and generalized superclass C,
where the attributes of C are {k,a1,…an} and k is the (primary) key, into relational schemas
using one of the four following options:
➢ Option 8A: Multiple relations-Superclass and subclasses
➢ Option 8B: Multiple relations-Subclass relations only
➢ Option 8C: Single relation with one type attribute
➢ Option 8D: Single relation with multiple type attributes
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8A: Multiple relations-Superclass and subclasses
➢ Create a relation L for C with attributes Attrs(L) = {k,a1,…an} and PK(L) = k.

➢ Create a relation Li for each subclass Si, 1 < i < m, with the attributes
Attrs(Li) = {k} U {attributes of Si} and PK(Li)=k.

➢ This option works for any specialization (total or partial, disjoint of over-
lapping).
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8A: Multiple relations-Superclass and subclasses
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8B: Multiple relations-Subclass relations only
➢ Create a relation Li for each subclass Si, 1 < i < m, with the attributes
Attr(Li) = {attributes of Si} U {k,a1…,an} and PK(Li) = k.

➢ This option only works for a specialization whose subclasses are total (every entity in the
superclass must belong to (at least) one of the subclasses).

➢ Specialization has disjointedness constraint


Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8B: Multiple relations-Subclass relations only
Create a relation Li for each subclass Si, 1 < i < m, with the attributes Attr(Li) = {attributes of Si} U
{k,a1…,an} and PK(Li) = k.
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8C: Single relation with one type attribute

➢ Create a single relation L with attributes


Attrs(L) = {k,a1,…an} U {attributes of S1} U…U {attributes of Sm} U {t} and PK(L) = k.

➢ The attribute t is called a type (or discriminating) attribute that indicates the subclass
to which each tuple belongs. Subclasses are disjoint
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option
➢ 8C:a Single
Create relationLwith
single relation withone type attribute
attributes
Attrs(L) = {k,a1,…an} U {attributes of S1} U…U {attributes of Sm} U {t} and PK(L) = k.
Mapping of EER to Relational Model
Step8: Options for Mapping Specialization or Generalization.
Option 8D: Single relation with multiple type attributes

➢ Create a single relation schema L with attributes


Attrs(L) = {k,a1,…an} U {attributes of S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK(L) = k.
Each ti, 1 < I < m, is a Boolean type attribute indicating whether a tuple belongs to the
subclass Si.

Subclasses are overlapping


Will also work for a disjoint specialization
Mapping of EER to Relational Model
➢Step8:
Create a singleforrelation
Options Mappingschema L with attributes
Specialization or Generalization.
Option=8D:
Attrs(L) {k,aSingle relation with multiple type attributes
1,…an} U {attributes of S1} U…U {attributes of Sm} U {t1, t2,…,tm} and PK(L) = k.
Each ti, 1 < I < m, is a Boolean type attribute indicating whether a tuple belongs to the
subclass Si.
62
MODULE NO:-3 Relational Model and Relational Algebra :

3.1. Introduction to the Relational Model,


3.2. Relational schema
3.3. concept of keys
3.4. Mapping the ER and EER Model to the
Relational Model
3.5. Relational Algebra –
unary and set operations,
Relational Algebra operations
RELATIONAL ALGEBRA
Query is a question or requesting information. Query language is a language which is
used to retrieve information from a database.
Query language is divided into two types −
➢ Procedural language
➢ Non-procedural language
RELATIONAL ALGEBRA
Procedural language
➢ Information is retrieved from the database by specifying the sequence of operations
to be performed.
➢ For Example − Relational algebra.
➢ Structure Query language (SQL) is based on relational algebra.
➢ Relational algebra consists of a set of operations that take one or two relations as an
input and produces a new relation as output.
RELATIONAL
ALGEBRA
RELATIONAL ALGEBRA
Selection Operator-
The SELECTION operation is used to select a subset of the tuples from a relation that satisfy
a selection condition.
The SELECT operation is denoted by σ<selection-condition>(R)

The SELECT operation is a filter that keeps only those tuples that satisfy a qualifying
condition/selection condition.

The SELECT operation can also be visualized as a horizontal partition of the relation into
two sets of tuples-those tuples that satisfy the condition and are selected, and those tuples
that do not satisfy the condition and are discarded
RELATIONAL ALGEBRA
Important Points-
Point-01:

•We may use logical operators like ∧ , ∨ , ! and relational operators like = , ≠ , > , < , <= , >=
with the selection condition.

Point-02:

•Selection operator only selects the required tuples according to the selection condition.
•It discards the unselected tuples.
•Its called Horizontal Partition.
RELATIONAL ALGEBRA
Point-03:
Selection operator is commutative in nature i.e.
σ A ∧ B (R) = σ B ∧ A (R)
OR
σ B (σ A(R)) = σ A (σ B(R))
Point-04:
Degree of the relation from a selection operation is same as degree of the input relation.
Point-05:
The number of rows returned by a selection operation is obviously less than or equal to the
number of rows in the original table.
Thus,Minimum Cardinality = 0 and Maximum Cardinality = |R|
RELATIONAL ALGEBRA

σ<selection-condition>(R)
<Attribute name><comparison operator><Constant value>
or
<Attribute name><comparison operator><Attribute name>

σ<selection-condition>or<selection-condition>(R)
• Boolean operators like:-AND ,OR,NOT
RELATIONAL ALGEBRA
Example 1:-Retrieve Person with stamp collection as his hobby from the given relation Person
RELATIONAL ALGEBRA
Example 2:-Retrieve customer who lives in USA

𝝈
Country=USA Customer
RELATIONAL ALGEBRA
Example 3:-Retrieve customer who lives in USA and has credit limit over 5000

𝝈 Customer
Country=USA and creditLimit>5000
RELATIONAL ALGEBRA
Projection Operator-

➢ The PROJECT operation, selects certain columns from the table and discards the other
columns.

➢ If we are interested in only certain attributes of a relation, we use the PROJECT


operation to project the relation over these attributes only.

➢ The result of the PROJECT operation can hence be visualized as a vertical partition of
the relation. The PROJECT operation is denoted by
RELATIONAL ALGEBRA
Important Points-
Point-01:
➢ The degree of output relation (number of columns present) is equal to the number of
attributes mentioned in the attribute list.
Point-02:
➢ Projection operator automatically removes all the duplicates while projecting the output
relation.
➢ So, cardinality of the original relation and output relation may or may not be same.
➢ If there are no duplicates in the original relation, then the cardinality will remain same
otherwise it will surely reduce.
RELATIONAL ALGEBRA
Point-03:
➢ If attribute list is a super key on relation R, then we will always get the same number of
tuples in the output relation.
➢ This is because then there will be no duplicates to filter.
Point-04:
➢ Projection operator does not obey commutative property i.e.
π <list2> (π <list1> (R)) ≠ π <list1> (π <list2> (R))
Point-05:
➢ Following expressions are equivalent because both finally projects columns of list-1
π <list1> (π <list2> (R)) = π <list1> (R)
RELATIONAL ALGEBRA
Example 4:- Retrieve persons name and hobby
RELATIONAL ALGEBRA
Example 5:- Retrieve the first name, last name, and salary of all employees who work in department number 5
RELATIONAL ALGEBRA
Example 5:- Retrieve the first name, last name, and salary of all employees who work in department number 5
RELATIONAL ALGEBRA
Example 5:- Retrieve the first name, last name, and salary of all employees who work in department number 5
RELATIONAL ALGEBRA
RENAME operation-which can rename either the relation name or the attribute names, or
both-in a manner similar to the way we defined SELECT and PROJECT.
The general RENAME operation is denoted by symbol P (rho) any of the following three
forms
𝝆S(B1,B2…….Bn) ( R )
S is the new relation name, and Bl , B2, •• ., Bn are the new attribute names. This expression
renames both the relation and its attributes
𝝆S ( R ) This renames the relation only, and
𝝆(B1,B2,B3……Bn) ( R ) This renames the attributes only. If the attributes of R are (AI' A2, ••• ,
An) in that order, then each Ai is renamed as Bj •
83
84
RELATIONAL
ALGEBRA
RELATIONAL ALGEBRA
RELATIONAL ALGEBRA
RELATIONAL ALGEBRA

Condition For Using Set Theory Operators

To use set theory operators on two relations,


The two relations must be union compatible.
Union compatible property means-
•Both the relations must have same number of attributes.
•The attribute domains (types of values accepted by attributes) of both the relations
must be compatible.
RELATIONAL ALGEBRA
1. Union Operator (∪)-

Let R and S be two relations.


Then-
➢ R ∪ S is the set of all tuples belonging to either R or S or both.
➢ In R ∪ S, duplicates are automatically removed.
➢ Union operation is both commutative and associative.
RELATIONAL ALGEBRA
Example-
RELATIONAL ALGEBRA
2. Intersection Operator (∩)-

Let R and S be two relations.


Then-
➢ R ∩ S is the set of all tuples belonging to both R and S.
➢ In R ∩ S, duplicates are automatically removed.
➢ Intersection operation is both commutative and associative.
RELATIONAL ALGEBRA
Example-
RELATIONAL ALGEBRA
3. Difference Operator (-)-

Let R and S be two relations.


Then-
➢ R – S is the set of all tuples belonging to R and not to S.
➢ In R – S, duplicates are automatically removed.
➢ Difference operation is associative but not commutative.
RELATIONAL ALGEBRA
Example-
RELATIONAL ALGEBRA ACTIVITY

Given two relations STUDENT & INSTRUCTOR as above Find


(i) STUDENT ∪ INSTRUCTOR
(ii) STUDENT ∩ INSTRUCTOR
(iii) STUDENT − INSTRUCTOR (iv)INSTRUCTOR - STUDENT
RELATIONAL ALGEBRA
ACTIVITY SOLUTION

(i) STUDENT ∪ INSTRUCTOR STUDENT ∩ INSTRUCTOR STUDENT − INSTRUCTOR INSTRUCTOR - STUDENT


RELATIONAL ALGEBRA
RELATIONAL ALGEBRA
Binary Operator-Cartesian product
➢ The CARTESIAN PRODUCT operation-also known as CROSS PRODUCT
or CROSS JOIN-which is denoted by ×.
➢ This is also a binary set operation, but the relations on which it is applied do not have to be
union compatible.
➢ This operation is used to combine tuples from two relations in a combinatorial fashion.
➢ In general, the result of R(A j , Az, ... , An) X S(Bj , Bz, ... , Bm) is a relation Q with degree
n + m attributes Q(Aj , Az' ... , An' Bj , Bz, ... , Bm), in that order.
➢ The resulting relation Q has one tuple for each combination of tuples-one from R and one
from S.
➢ Hence, if R has n tuples, and S has ns tuples, then R x S will have n * ns tuples
R R
RELATIONAL ALGEBRA
Binary Operator-Cartesian product
RELATIONAL ALGEBRA
Binary Operator-Cartesian product
RELATIONAL ALGEBRA
RELATIONAL ALGEBRA JOIN
➢ Database joins are the alternate to the Cartesian product operation of the relational
algebra concept.
➢ But, the logic behind the data set joins is same as that of a Cartesian product but, joins in
database includes the option for condition which needs to be satisfied in order to get the
desired results/output.
➢ The database joins has the ability of combining two or more data tables/tuples into a single
table/table only if the following conditions are satisfied.
➢ There must be a common attribute in both(tables which are participating) tables.
➢ Join condition must be satisfied.
➢ Database joins can be broadly classified into two categories which are
further categorized into sub categories. All of them are explained below.
RELATIONAL ALGEBRA JOIN
RELATIONAL ALGEBRA INNER JOIN
RELATIONAL ALGEBRA JOIN
RELATIONAL ALGEBRA JOIN
RELATIONAL ALGEBRA INNER-JOIN
RELATIONAL ALGEBRA INNER JOIN-THETA

If the two relations are R and S then join Syntax is


R ⋈ <join-condition> S,
Where <join condition > is specified on attributes from the two relations R and S and is
evaluated for each combination of tuples. Each tuple combination for which the join
condition evaluates to TRUE is included in the resulting relation Q as a single combined
tuple.
Multiple conditions can be specified
<condition1> and <condition2> or<condition 3> where each condition is of the form Ai 𝜃 Bj
, Ai is an attribute of R, Bj is an attribute of S, Ai and Bj have the same domain, and
𝜃(theta) is one of the comparison operators {=,<, ≤, ≥, >, ≠ }.
RELATIONAL ALGEBRA INNER JOIN-THETA
Retrieve employee department names where salary is greater than 25000

R1 EMPLOYEE ⋈ DEPARTMENT
<EMPLOYEE . DNO=DEPARTMENT.DNO> AND< SALARY>25000>
RELATIONAL ALGEBRA INNER JOIN-EQUI

The most common use of JOIN involves join conditions with equality
comparisons only. Such a JOIN, where the only comparison operator used
is =, is called an EQUIJOIN.

R1 CUTOMER ⋈ SHIPPER
<CUSTOMER . COUNTRY=SHIPPER.COUNTRY>
RELATIONAL ALGEBRA EQUI JOIN
Retrieve employee department names where salary is greater than 25000

DEPARTMENT

EMPLOYEE
RELATIONAL ALGEBRA EQUI JOIN
Retrieve employee department names where salary is greater than 25000
RELATIONAL ALGEBRA NATURAL JOIN

➢ Notice that in the result of an EQUI-JOIN we always have one or more pairs of attributes
that have identical values in every tuple R because of the equality join condition specified
on these two attributes.
➢ Because one of each pair of attributes with identical values is superfluous, a new
operation called NATURAL JOIN-denoted by *-was created to get rid of the second
(superfluous) attribute in an EQUI]OIN condition’s.
➢ The standard definition of NATURAL JOIN requires that the two join attributes (or each
pair of join attributes) have the same name in both relations. If this is not the case, a
renaming operation is applied first.
RELATIONAL ALGEBRA NATURAL JOIN

Table_a ∗ table_b
RELATIONAL ALGEBRA NATURAL JOIN

EMPLOYEE * DEPENDENTS
RELATIONAL ALGEBRA DIVISION OPERATOR
RELATIONAL ALGEBRA DIVISION OPERATOR

RESULT T
A
RELATIONAL ALGEBRA DIVISION OPERATOR
RELATIONAL ALGEBRA DIVISION OPERATOR
RELATIONAL ALGEBRA DIVISION OPERATOR
RELATIONAL ALGEBRA DIVISION OPERATOR
RELATIONAL ALGEBRA DIVISION OPERATOR

÷
RELATIONAL ALGEBRA DIVISION OPERATOR

÷
RELATIONAL ALGEBRA JOIN
RELATIONAL ALGEBRA OUTER JOIN

➢ Theta Join, Equijoin, and Natural Join are called inner joins.

➢ An inner join includes only those tuples with matching attributes and the rest are
discarded in the resulting relation.

➢ Therefore, we need to use outer joins to include all the tuples from the participating
relations in the resulting relation.

➢ There are three kinds of outer joins − left outer join, right outer join, and full outer join.
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
Left Outer Join(R S)
➢ All the tuples from the Left relation, R, are included in the resulting relation.
➢ If there are tuples in R without any matching tuple in the Right relation S, then the
S-attributes of the resulting relation are made NULL.
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
Right outer join:
➢ Right outer join contains the set of tuples of all combinations in R and S that are equal on
their common attribute names.
➢ In right outer join, tuples in S have no matching tuples in R.
➢ It is denoted by ⟖.
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN

Full outer join:


➢ Full outer join is like a left or right join except that it contains all rows from both
tables.
➢ In full outer join, tuples in R that have no matching tuples in S and tuples in S that
have no matching tuples in R in their common attribute name.
➢ It is denoted by ⟗.
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA OUTER JOIN
RELATIONAL ALGEBRA ACTIVITY ON OUTER JOIN
Be good do good

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy