Dbms Mod2
Dbms Mod2
Module 2
//For all the numerical refer ma’am ppt ch2_1//
● Relational Algebra
1. Select Operation:
1. Notation: σ p(r)
Where:
Input:
1. σ BRANCH_NAME="perryride" (LOAN)
Output:
2. Project Operation:
○ This operation shows the list of those attributes that we wish to appear in the
result. Rest of the attributes are eliminated from the table.
○ It is denoted by ∏.
1. Notation: ∏ A1, A2, An (r)
Where
Input:
Output:
NAME CITY
Jones Harrison
Smith Rye
Hays Harrison
Curry Rye
Johnson Brooklyn
Brooks Brooklyn
3. Union Operation:
○ Suppose there are two tuples R and S. The union operation contains all the tuples
that are either in R or S or both in R & S.
1. Notation: R ∪ S
Example:
DEPOSITOR RELATION
CUSTOMER_NAME ACCOUNT_NO
Johnson A-101
Smith A-121
Mayes A-321
Turner A-176
Johnson A-273
Jones A-472
Lindsay A-284
BORROW RELATION
CUSTOMER_NAME LOAN_NO
Jones L-17
Smith L-23
Hayes L-15
Jackson L-14
Curry L-93
Smith L-11
Williams L-17
Input:
Output:
CUSTOMER_NAME
Johnson
Smith
Hayes
Turner
Jones
Lindsay
Jackson
Curry
Williams
Mayes
4. Set Intersection:
○ Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in both R & S.
○ It is denoted by intersection ∩.
1. Notation: R ∩ S
Input:
Output:
CUSTOMER_NAME
Smith
Jones
5. Set Difference:
○ Suppose there are two tuples R and S. The set intersection operation contains all
tuples that are in R but not in S.
1. Notation: R - S
Input:
Output:
CUSTOMER_NAME
Jackson
Hayes
Willians
Curry
6. Cartesian product
○ The Cartesian product is used to combine each row in one table with each row in
the other table. It is also known as a cross product.
○ It is denoted by X.
1. Notation: E X D
Example:
EMPLOYEE
1 Smith A
2 Harry C
3 John B
DEPARTMENT
DEPT_NO DEPT_NAME
A Marketing
B Sales
C Legal
Input:
1. EMPLOYEE X DEPARTMENT
Output:
E EMP_N EMP_ DEP DEPT_N
MP AME DEPT T_N AME
_I O
D
1 Smith A A Marketing
1 Smith A B Sales
1 Smith A C Legal
2 Harry C A Marketing
2 Harry C B Sales
2 Harry C C Legal
3 John B A Marketing
3 John B B Sales
3 John B C Legal
7. Rename Operation:
The rename operation is used to rename the output relation. It is denoted by rho (ρ).
Example: We can use the rename operator to rename STUDENT relation to STUDENT1.
● ρ(STUDENT1, STUDENT)
Commercial
In Open Source
Database are that
Database anyone
which has been
Focus can easily view
created for
the Source code
Commercial
of it.
purpose only.
Examples:
Example MYSQL, Examples: Oracle,
s PostgreSQL, DB2, Splunk etc.
MongoDB etc.
Technica It provide
It provide limited
l guaranteed
technical support.
support technical support.
In this Software is
In this software is
available under
License available under
high licensing
free licensing.
cost.
premium difficulties
Benefits
solution, a develop.
source usually
or more guarantee.
functionality is ● Developers
can be updates as
security allows
concerns, businesses to
technical
outages and
failures.
● Volunteer
Technical
support
● Because of
Compatibility
cannot be guidelines
assured that it
Source code
will work in
cannot be
each user’s
modified so
Drawba environment
cks extra cost is
due to
incurred for
compatibility
getting more
difficulties.
functionality of
● Professionals
premium
are required to
features
manage and
even install
the essential
infrastructure
because some
of these
difficulties
vary from
software to
hardware.
● Open source
also poses a
significant
security risk
because some
of it can easily
contain
security
exploits.
DATA DEPENDENCY-
Dependencies in DBMS is a relation between two or more attributes. In more simple
terms we can say that some data values are dependent on other data values in
order to get recognized.
Example-
Roll no→ name
In this example Roll no. will be unique for each student but two students can have the same
name. Suppose we want to know about the student whose name is Amit but there are two
students with the name Amit, so in this case, the name doesn’t uniquely identifies the
student(we have confusion about which student’s information we want). But if we take Roll
no.(say 101) then we will get information from one student whose name is Amit and Roll no.
is 101, hence no confusion. Therefore the name is dependent on Roll no.
● 1. Functional Dependency
● 2. Fully-Functional Dependency
● 3. Transitive Dependency
● 4. Multivalued Dependency
● 5. Partial Dependency
● Armstrong’s axioms
dependencies.
database.
A. Primary Rules
Rule Reflexivity
1 If A is a set of attributes and B is a subset of A, then A holds B. { A → B }
Rule Augmentation
2 If A hold B and C is a set of attributes, then AC holds BC. {AC → BC}
It means that attribute in dependencies does not change the basic
dependencies.
Rule Transitivity
3 If A holds B and B holds C, then A holds C.
If {A → B} and {B → C}, then {A → C}
A holds B {A → B} means that A functionally determines B.
B. Secondary Rules
Rule 1 Union
If A holds B and A holds C, then A holds BC.
If{A → B} and {A → C}, then {A → BC}
Rule 2 Decomposition
If A holds BC and A holds B, then A holds C.
If{A → BC} and {A → B}, then {A → C}
A set of functional dependencies with the above three properties are also
called as Canonical or Minimal.
Trivial Functional Dependency
Example:
Consider relation E = (P, Q, R, S, T, U) having set of Functional
Dependencies (FD).
P→Q P→R
QR → S Q→T
QR → U PR → U
1. P → T
2. PR → S
3. QR → SU
4. PR → SU
Solution:
1. P → T
In the above FD set, P → Q and Q → T
So, Using Transitive Rule: If {A → B} and {B → C}, then {A → C}
∴ If P → Q and Q → T, then P → T.
P→T
2. PR → S
In the above FD set, P → Q
As, QR → S
So, Using Pseudo Transitivity Rule: If{A → B} and {BC → D}, then
{AC → D}
∴ If P → Q and QR → S, then PR → S.
PR → S
3. QR → SU
In above FD set, QR → S and QR → U
So, Using Union Rule: If{A → B} and {A → C}, then {A → BC}
∴ If QR → S and QR → U, then QR → SU.
QR → SU
4. PR → SU
So, Using Pseudo Transitivity Rule: If{A → B} and {BC → D}, then
{AC → D}
∴ If PR → S and PR → U, then PR → SU.
PR → SU
● Normal forms
❖ Numerical from yt
● Dependency preservation
❖ Numerical from yt
● Lossless design
❖ numerical
● Evaluation of relational algebra preservation
❖ Numerical
● Query equivalence
Refer GFG:
https://www.geeksforgeeks.org/query-optimization-in-relation
al-algebra/
● Join strategy
Join is an operation in DBMS(Database Management System) that combines the row of two or
more tables based on related columns between them. The main purpose of Join is to retrieve
the data from multiple tables in other words Join is used to perform multi-table query. It is
denoted by ⨝.
Syntax 1
R3 <- ⨝(R1) <join_condition> (R2)
where R1 and R2 are two relations to be join and R3 is a relation that will holds the result of join
operation.
Example
Temp <- ⨝(student) S.roll==E.roll(Exam)
where S and E are alias of the student and exam respectively
Types of Join
1. Inner Join
2. Outer join
Inner join
Inner Join is a join operation in DBMS that combines two or more table based on related
columns and return only rows that have matching values among tables.Inner join of two types.
● Equi Join
● Natural Join
Equi Join
Equi Join is a type of Inner join in which we use euivalence(‘=’) condition in join condition
Example:
Table A
Column A Column B
a a
a b
Table B
Column A Column B
a a
a c
Column A Column B
a a
Natural Join
Natural join is a type of inner join in which we not need of any comparison operators. In natural
join columns should have the same name and domain. There should be at least one common
attribute between two tables.
Eample:
Table A
Number Square
2 4
3 9
Table B
Number Cube
2 8
3 27
A⨝B
Number Square Cube
2 4 8
3 9 27
Outer Join
Outer join is a type of join that retrieve matching as well as non-maching records from related
tables.
There three types of outer join
● Left outer join
● Right outer join
● Full outer join
Number Square
2 4
3 9
4 16
Table B
Number Cube
2 8
3 27
5 75
A⟕B
Result:
2 4 8
3 9 27
4 16 –
2 4 8
3 9 27
5 – 75
2 4 8
3 9 27
4 16 –
5 – 75