DBDA
(Database Design and Applications)
CH3
By: Prof. Ganesh Ingle
Session objective
INTRODUCTION
Relational Query Languages
Formal Query Languages
Introduction to relational algebra
Set Operators Join operator
Aggregate functions,Grouping
Relational Calculus concepts
Introduction to Structured Query Language (SQL)
Features of SQL,DDL Statements
Relational Query Languages
Relational Algebra:
Relational algebra is a procedural query language, which takes instances
of relations as input and yields instances of relations as output. It uses
operators to perform queries. An operator can be either unary or binary.
They accept relations as their input and yield relations as their output.
Relational algebra is performed recursively on a relation and
intermediate results are also considered relations.
The fundamental operations of relational algebra are as follows −
Select
Project
Union
Set different
Cartesian product
Rename
Relational Query Languages
Relational Algebra:
In Non-procedural query language, user instructs the system to produce the desired result without telling the
step by step process. Here users tells what data to be retrieved from database but doesn't tell how to retrieve it.
In procedural query language, user instructs the system to perform a series of operations to produce the
desired results. Here users tells what data to be retrieved from database and how to retrieve it. ... then it is a
procedural language.
Relational Query Languages
Relational Model vs RDBMS:
Relation Model RDBMS
RA,RC SQL
Algo Code
Conceptual Real time
Theoretical Practical
Introduction to relational algebra
Relational algebra: Its formal query language associated with relational model
Introduction to relational algebra
Select:
SELECT (σ)
The SELECT operation is used for selecting a subset of the
tuples according to a given selection condition. Sigma(σ)Symbol
denotes it. It is used as an expression to choose tuples which
meet the selection condition. Select operator selects tuples that
satisfy a given predicate.
Introduction to relational algebra
Select:
Query1: Find the details of account having balance >=10000?
Query2: Find the details of Customer who lives in Pune?
Query3: Find the details of those loan having amount <=5000? and from Pimpri branch
Query4: Find the details of those branch details which are in Pune and having assets more than 10L
Introduction to relational algebra
Project:
Project(∏)
Introduction to relational algebra
Project:
Query1: Find all the Branch_Name of bank
Query2: Find all the account numbers wit its balance?
Query3: Find the names of all the customers who have loan?
Query1: Find all the details of branch?
Introduction to relational algebra
Project : Select combination
Query1: Find those account where balance is less than 1000?
Query2: Find those loan numbers which are from pune branch with amount >1000?
Query3: Find the branch name and branch city with assets more than 100000?
Introduction to relational algebra
Union (∪)/Intersection (∩)/ Difference (−)
Query1: Find names of those customer having account or loan or
both?
Query2: Find names of a branch who have account but not loan
Query3: Find the names of those customer who neither loan or an account?
Introduction to relational algebra
Cartesian Product
The Cartesian Product is also an operator which works on two
sets. It is sometimes called the CROSS PRODUCT or CROSS
JOIN.
It combines the tuples of one relation with all the tuples of the
other relation.
Account
AAN BNo Bal
101 x 50
102 y 70
103 z 100
Deposit
CN DAN
1 101
2 102
3 103
Account X Deposit
Account X Deposit
AAN BNo Bal CN DAN
101 x 50 1 101
101 x 50 2 102
101 x 50 3 103
102 y 70 1 101
102 y 70 2 102
102 y 70 3 103
103 z 100 1 101
103 z 100 2 102
103 z 100 3 103
Query: Find CustomerName having account balance<100
Introduction to relational algebra
Aggregate or Set Functions
• Aggregate or Set functions are introduced to relational
algebra to increase its expressive power.
• An aggregate function operates on a set of values (tuples)
and computes one single value as output.
•
• The Set Functions in Relational Algebra
 sum(): computes the sum of all values in the (numeric) set
 avg(): computes the average of all values in the (numeric) set
 max(): finds the maximum value of all values in the set
 min(): finds the minimum value of all values in the set
 any(): returns TRUE if set is not empty, otherwise (i.e., empty set), returns FALSE
 count(): returns the cardinaility (number of elements) in the set
Introduction to relational algebra
Aggregate or Set Functions
Query1: Find the sum of assets of all banches
Query2: Count distinct customer name having accounts
Query2: Find the branch city wise max assets?
Introduction to relational algebra
Joins
Joins :
Joins
Inner Join: o/p or result
contains matching tuples
Types:=
1.Theta Join
2.Equi-Join
3.Natural Join
Outer join : All the rows from
both or any relations
Types :=
1.Left outer
2.Right outer
3.Full outer
Introduction to relational algebra
Theta Joins
Introduction to relational algebra
Joins
Introduction to relational algebra
EQUI Joins
Introduction to relational algebra
Joins
Introduction to relational algebra
Outer Joins
Introduction to relational algebra
Left Outer Joins
Introduction to relational algebra
Right Outer Joins
Introduction to relational algebra
Full Outer Joins
Introduction to relational algebra
Joins
Introduction to relational algebra
Division
Introduction to relational algebra
Division
Introduction to relational algebra
Division
Introduction to relational algebra
Division
Introduction to SQL
Introduction to SQL
THANK YOU

Database Management System-session 3-4-5

  • 1.
    DBDA (Database Design andApplications) CH3 By: Prof. Ganesh Ingle
  • 2.
    Session objective INTRODUCTION Relational QueryLanguages Formal Query Languages Introduction to relational algebra Set Operators Join operator Aggregate functions,Grouping Relational Calculus concepts Introduction to Structured Query Language (SQL) Features of SQL,DDL Statements
  • 3.
    Relational Query Languages RelationalAlgebra: Relational algebra is a procedural query language, which takes instances of relations as input and yields instances of relations as output. It uses operators to perform queries. An operator can be either unary or binary. They accept relations as their input and yield relations as their output. Relational algebra is performed recursively on a relation and intermediate results are also considered relations. The fundamental operations of relational algebra are as follows − Select Project Union Set different Cartesian product Rename
  • 4.
    Relational Query Languages RelationalAlgebra: In Non-procedural query language, user instructs the system to produce the desired result without telling the step by step process. Here users tells what data to be retrieved from database but doesn't tell how to retrieve it. In procedural query language, user instructs the system to perform a series of operations to produce the desired results. Here users tells what data to be retrieved from database and how to retrieve it. ... then it is a procedural language.
  • 5.
    Relational Query Languages RelationalModel vs RDBMS: Relation Model RDBMS RA,RC SQL Algo Code Conceptual Real time Theoretical Practical
  • 6.
    Introduction to relationalalgebra Relational algebra: Its formal query language associated with relational model
  • 7.
    Introduction to relationalalgebra Select: SELECT (σ) The SELECT operation is used for selecting a subset of the tuples according to a given selection condition. Sigma(σ)Symbol denotes it. It is used as an expression to choose tuples which meet the selection condition. Select operator selects tuples that satisfy a given predicate.
  • 8.
    Introduction to relationalalgebra Select: Query1: Find the details of account having balance >=10000? Query2: Find the details of Customer who lives in Pune? Query3: Find the details of those loan having amount <=5000? and from Pimpri branch Query4: Find the details of those branch details which are in Pune and having assets more than 10L
  • 9.
    Introduction to relationalalgebra Project: Project(∏)
  • 10.
    Introduction to relationalalgebra Project: Query1: Find all the Branch_Name of bank Query2: Find all the account numbers wit its balance? Query3: Find the names of all the customers who have loan? Query1: Find all the details of branch?
  • 11.
    Introduction to relationalalgebra Project : Select combination Query1: Find those account where balance is less than 1000? Query2: Find those loan numbers which are from pune branch with amount >1000? Query3: Find the branch name and branch city with assets more than 100000?
  • 12.
    Introduction to relationalalgebra Union (∪)/Intersection (∩)/ Difference (−) Query1: Find names of those customer having account or loan or both? Query2: Find names of a branch who have account but not loan Query3: Find the names of those customer who neither loan or an account?
  • 13.
    Introduction to relationalalgebra Cartesian Product The Cartesian Product is also an operator which works on two sets. It is sometimes called the CROSS PRODUCT or CROSS JOIN. It combines the tuples of one relation with all the tuples of the other relation. Account AAN BNo Bal 101 x 50 102 y 70 103 z 100 Deposit CN DAN 1 101 2 102 3 103 Account X Deposit Account X Deposit AAN BNo Bal CN DAN 101 x 50 1 101 101 x 50 2 102 101 x 50 3 103 102 y 70 1 101 102 y 70 2 102 102 y 70 3 103 103 z 100 1 101 103 z 100 2 102 103 z 100 3 103 Query: Find CustomerName having account balance<100
  • 14.
    Introduction to relationalalgebra Aggregate or Set Functions • Aggregate or Set functions are introduced to relational algebra to increase its expressive power. • An aggregate function operates on a set of values (tuples) and computes one single value as output. • • The Set Functions in Relational Algebra  sum(): computes the sum of all values in the (numeric) set  avg(): computes the average of all values in the (numeric) set  max(): finds the maximum value of all values in the set  min(): finds the minimum value of all values in the set  any(): returns TRUE if set is not empty, otherwise (i.e., empty set), returns FALSE  count(): returns the cardinaility (number of elements) in the set
  • 15.
    Introduction to relationalalgebra Aggregate or Set Functions Query1: Find the sum of assets of all banches Query2: Count distinct customer name having accounts Query2: Find the branch city wise max assets?
  • 16.
  • 17.
    Joins : Joins Inner Join:o/p or result contains matching tuples Types:= 1.Theta Join 2.Equi-Join 3.Natural Join Outer join : All the rows from both or any relations Types := 1.Left outer 2.Right outer 3.Full outer
  • 18.
    Introduction to relationalalgebra Theta Joins
  • 19.
  • 20.
    Introduction to relationalalgebra EQUI Joins
  • 21.
  • 22.
    Introduction to relationalalgebra Outer Joins
  • 23.
    Introduction to relationalalgebra Left Outer Joins
  • 24.
    Introduction to relationalalgebra Right Outer Joins
  • 25.
    Introduction to relationalalgebra Full Outer Joins
  • 26.
  • 27.
  • 28.
  • 29.
  • 30.
  • 31.
  • 32.
  • 33.