Unit-3
Unit-3
Relational Query
Languages
Looping
Outline
• Structure of Relational Databases
• Key
• Relational Algebra
• Fundamental Operators and Syntax
Selection
Projection
Cross Product OR Cartesian Product
Joins
Set Operators
Division
Rename
Aggregate Functions
• Open Source and Commercial DBMS
Structure of Relational
Databases
Section - 1
Structure of Relational Databases
Columns Table (Relation): A database object
(5) that holds a collection of data for a
specific topic.
Stud Table consist of rows and columns.
Attributes:
ent
Roll Branc Semes SP
Title of Name Column (Attribute): The vertical
column No h ter I
component of a table. A column has a
101 Raju CE 3 8 name and a particular data type; e.g.
102 Mites CI 3 7 varchar, decimal, integer, datetime etc.
Cardinality = No of
Rows or h Record (Tuple): The horizontal
Tuples or component of a table, consisting of a
103 Mayu CE 3 6
Records sequence of values, one for each
r
tuples (7)
(7) column of the table. It is also known as
104 Niles EE 3 9 row.
h
A database consists of a collection of
105 Hites CI 3 7 tables (relations), each having a unique
h name.
Degree = No of
Domain 106is a setTarun ME
columns
of all 3 unique 8
(5)
possible values for
a specific107
column.Sures CE 3 9
Domain of Branch h attribute is (CE, CI, ME, EE)
4
Key
Section - 2
Super Key
A super key is a set of one or more attributes whose values uniquely
identifies each record within a relation (table).
Super Key Super Key
Super Key
(RollNo, Branch, (SPI, Name,
EnrollNo
Sem) BL)
Roll Branc Se SP B
EnrollNo Name
No h m I L
190540107 101 CE 3 8 Raju 0
001
190540107 102 CE 3 7 Mites 1
002 h
190540106 101 CI 3 6 Mayu 2
001 r
190540106 102 CI 3 9 Niles 0
002 h
180540107 101 CE 5 7 Hites 1
001 h
6
Candidate Key
A candidate key is a subset of a super key.
A candidate key is a single attribute or the least combination of attributes
that uniquely identifies each record in the table.
A candidate key is a super key for which no proper subset is a super
key.
Every candidate key is a super key but every super key is not a
Candidate Candidate Key
candidate key.
Key (RollNo, Branch,
EnrollNo Sem)
Roll Branc Se SP B
EnrollNo Name
No h m I L
190540107 101 CE 3 8 Raju 0
001
180540107 101 CE 5 7 Mites 1
002 h
190540106 101 CI 3 6 Mayu 2
001 r 7
Primary Key
A primary key is a candidate key that is chosen by database
designer to identify tuples uniquely in a relation (table).
Primary
Key
Candidate Candidate Key
Key (RollNo, Branch,
EnrollNo Sem)
Roll Branc Se SP B
EnrollNo Name
No h m I L
190540107 101 CE 3 8 Raju 0
001
180540107 101 CE 5 7 Mites 1
002 h
190540106 101 CI 3 6 Mayu 2
001 r 8
Alternate Key
An alternate key is a candidate key that is not chosen by database
designer to identify tuples uniquely in a relation.
Primary Alternate
Key Key
Candidate Candidate Key
Key (RollNo, Branch,
EnrollNo Sem)
Roll Branc Se SP B
EnrollNo Name
No h m I L
190540107 101 CE 3 8 Raju 0
001
180540107 101 CE 5 7 Mites 1
002 h
190540106 101 CI 3 6 Mayu 2
001 r 9
Primary Key rules
A primary key may have one or more attributes.
There is only one primary key in the relation (table).
A primary key attribute value cannot be NULL.
Generally, the value of a primary key attribute does not change.
10
Foreign Key
A foreign key is used to link two relations (tables).
A foreign key is an attribute or collection of attributes in one table that
refers to the primary key in another table.
A table containing the foreign key is called the child table, and the table
containing the primary key is called the parent table.
Parent Child
Table Table
Stud Proje
ent Nam Branc Se ct
EnrollNo Projec
e h m Title EnrollNo
tID
190540107 Raju CE 3 101 Bank 190540107
001 001
190540107 Mites CE 3 102 College 190540107
002 h 002
190540107 Niles CE 3 103 School 190540107
003 h 003 11
Relational Algebra
Operations
Section - 3
Relational Algebra Operations
Operator Description
Selection Display particular rows/records/tuples from a relation
Projection Display particular columns from a relation
Cross Product Multiply each tuples of both relations
Combine data or records from two or more tables
1. Natural Join / Inner Join
Joins 2. Outer Join
1. Left Outer Join 2. Right Outer Join 3. Full Outer Join
13
Relational Algebra
Operations
Selection Operator
Section - 3.1
Selection Operator
Symbol: σ (Sigma)
Notation: σ (Relation)
condition
Operation: Selects tuples from a relation that satisfy a given
condition.
Operators: =, <>, <, >, <=, >=, Λ (AND), V (OR)
Exam σ
Display the detail of students belongs to Answ Branch=‘CE’
ple “CE” Branch. er (Student)
Stud Outp
ent
Roll Nam Branc SP ut
Roll Nam Branc SP
No e h I No e h I
101 Raju CE 8 101 Raju CE 8
102 Mites ME 9 104 Meet CE 9
h
103 Niles CI 9
h
104 Meet CE 9 15
Selection Operator [σ condition (Relation)]
er (Student)
Outp
ut
Roll Nam Branc SP
No e h I
104 Meet CE 9
16
Selection Operator [σ condition (Relation)]
Exam Display the detail of students belongs to either “CI”
ple or “ME” Branch.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104 σBranch=‘CI’
Answ Meet CE 9
V Branch=‘ME’
er (Student)
Outp
ut
Roll Nam Branc SP
No e h I
102 Mites ME 9
h
103 Niles CI 9 17
Selection Operator [σ condition (Relation)]
Exam Display the detail of students whose SPI
ple between 7 and 9.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104 σSPI>7CEΛ SPI<99
Answ Meet
er (Student)
Outp
ut
Roll Nam Branc SP
No e h I
101 Raju CE 8
18
Relational Algebra
Operations
Projection Operator
Section - 3.2
Projection Operator
Symbol: ∏ (Pi)
Notation: ∏
attribute set (Relation)
Operation: Selects specified attributes of a relation.
It removes duplicate tuples (records) from the result.
Exam Display RollNo, Name and Branch of Answ ∏ RollNo, Name, Branch
ple all students. er (Student)
Stud Outp
ent
Roll Nam Branc SP ut
Roll Nam Branc
No e h I No e h
101 Raju CE 8 101 Raju CE
102 Mites ME 9 102 Mites ME
h h
103 Niles CI 9 103 Niles CI
h h
104 Meet CE 9 104 Meet CE 20
Combined Projection & Selection Operation
Exam Display RollNo, Name & Branch of “ME”
ple Branch students.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104
Step- Meet σ CE
Branch=‘ME’ 7 Answ ∏ RollNo, Name, Branch (σBranch=‘ME’
1 (Student) er (Student))
Outpu Outpu
t-1
Roll Nam Branc SP t-2
Roll Nam Branc
No e h I No e h
102 Mites ME 9 102 Mites ME
h h
21
Combined Projection & Selection Operation
Exam Display Name, Branch and SPI of students whose SPI
ple is more than 8.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104
Step- Meet σSPI>8CE 7 Answ ∏ Name, Branch, SPI (σSPI>8
1 (Student) er (Student))
Outpu Outpu
t-1
Roll Nam Branc SP t-2
Nam Branc
SPI
No e h I e h
102 Mites ME 9 Mites ME 9
h h
103 Niles CI 9 Niles CI 9 22
Combined Projection & Selection Operation
Exam Display Name, Branch and SPI of students who belongs to “CE” Branch and
ple SPI is more than 7.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104
Step- Meet σBranch=‘CE’
CE 7
Λ SPI>7 Answ ∏ Name, Branch, SPI (σBranch=‘CE’ Λ SPI>7
1 (Student) er (Student))
Outpu Outpu
t-1
Roll Nam Branc SP t-2
Nam Branc
SPI
No e h I e h
101 Raju CE 8 Raju CE 8
23
Combined Projection & Selection Operation
Exam Display Name of students along with their Branch who belong to either “ME”
ple Branch or “CI” Branch.
Stud
ent
Roll Nam Branc SP
No e h I
101 Raju CE 8
102 Mites ME 9
h
103 Niles CI 9
h
104
Step- Meet σBranch=‘ME’
CE 7
V Branch=‘CI’ Answ ∏ Name, Branch (σBranch=‘ME’ V Branch=‘CI’
1 (Student) er (Student))
Outpu Outpu
t-1
Roll Nam Branc SP t-2
Nam Branc
No e h I e h
102 Mites ME 9 Mites ME
h h
103 Niles CI 9 Niles CI 24
Relational Algebra
Operations
Cartesian Product / Cross
Product
Section - 3.3
Cartesian Product / Cross Product
Symbol: X (Cross)
Notation: Relation-1 (R1) X Relation-2 (R2) OR Algebra-1 X Algebra-2
Operation: It will multiply each tuples of Relation-1 to each tuples of
Relation-2.
Attributes of Resultant Relation = Attributes of R1 + Attributes of R2
Tuples of Resultant Relation = Tuples of R1 * Tuples of R2
Answ (Student) X
Exam er (Result)
Perform Cross Product between Student
ple
Stud and Result. Resu Outp
ent
RN Nam Branc lt
RN SP ut
Student. Nam Branc Result. SP
o e h o I RNo e h RNo I
10 Raju CE 10 8 101 Raju CE 101 8
1 1
101 Raju CE 102 9
10 Mites ME 10 9
If2 bothh relations have some attribute
2 with the same 102 Mites ME 101 8
name, it can be distinguished by combing relation- h
name.attribute-name. 102 Mites ME 102 9
26
Cartesian Product / Cross Product Example
Consider only selected
Exam Perform Cross Product between Student attributes
ple and Result. • Student – RNo, Name and
Stud Resu Branch
ent
RN Nam Branc Se lt
RN SP B Ran • Result – RNo, SPI and BL
o e h m o I L k
10 Raju CE 3 10 8 1 2
1 1
10 Mites ME 5 10 9 0 1
2 h
Answ ∏ RNo, Name, Branch (Student)
3 X ∏ RNo, SPI, BL
er (Result)
Outp
ut
Student. Nam Branc Result. SP B
RNo e h RNo I L
101 Raju CE 101 8 1
101 Raju CE 103 9 0
102 Mites ME 101 8 1
h
102 Mites ME 103 9 0
27
Cartesian Product / Cross Product Example
Exam Perform Cross Product between Student Consider only selected tuples
• Student – Branch=‘CE’ and
ple and Result.
Stud Resu Sem=3
ent lt • Result – SPI>7 and BL<1
RN Nam Branc Se RN SP B Ran
o e h m o I L k
10 Raju CE 3 10 8 1 2
1 1
10 Mites ME 5 10 9 0 1
2 h 3
10 Om CE 3 10 7 2 3
Answ σBranch=‘CE’ Λ Sem=3 X σSPI>7 Λ
3 5
(Student)
10
er Dhar CE 5
BL<1 (Result)
4
Outpa
ut
Student. Nam Branc Se Result. SP B Ran
RNo e h m RNo I L k
101 Raju CE 3 103 9 0 1
103 OM CE 3 103 9 0 1
28
Relational Algebra
Operations
Natural Join / Inner Join
Section - 3.4
Natural Join / Inner Join
Symbol:
Notation: Relation-1 (R1) Relation-2 (R2) OR Algebra-1 Algebra-2
Operation: Natural join will retrieve consistent data from multiple
relations.
It combines records from different relations that satisfy a given condition.
Steps performed in
Natural Join
Steps Description
Step – 1 It performs Cartesian Product
Step – 2 Then it deletes inconsistent tuples
Then it removes an attribute from duplicate
Step – 3
attributes
30
Natural Join / Inner Join Example
Exam Perform Natural Join between Student Answ (Student)
ple and Result. er (Result)
Stud Resu Outp
ent
RN Nam Branc lt
RN SP ut
RN Nam Branc SP
o e h o I o e h I
10 Raju CE 10 8 10 Raju CE 8
1 1 To perform a Natural
1 Join there must be one
10 Mites ME 10 9 common attribute (column) between two
Steps
2 h performed in 3 relations.
Natural Join
Step:1 Perform Cross Step:2 Removes
Product
Student. Nam Branc Result. SP inconsistent
Student. Nam tuples
Branc Result. SP
RNo e h RNo I RNo e h RNo I
101 Raju CE 101 8 101 Raju CE 101 8
Step:3 Removes an attribute
101 Raju CE 103 9
from duplicate
RN Nam Branc SP
102 Mites ME 101 8 o e h I
h
10 Raju CE 8
102 Mites ME 103 9 1
h 31
Natural Join / Inner Join Example
Exam Perform Natural Join between Branch Answ (Branch)
ple and Faculty. er (Faculty)
Bran Facul Outp
ch
BI BNa ty
FI FNa BI ut
BI Bnam HO FI FNa
HOD
D me D me D D e D D me
1 CE Shah 10 Raj 1 1 CE Sha 10 Raj
1 h 1
2 ME Patel
10 Meet 2 2 ME Pate 10 Meet
3 l 3
To perform a Natural Join there must be one common
attribute (column) between two relations.
32
Write down relational algebra for the following
tables/relations
Relations
Student (Rno, Sname, Address, City, Mobile)
Department (Did, Dname)
Academic (Rno, Did, SPI, CPI, Backlog)
Guide (Rno, PName, Fid)
Faculty (Fid, Fname, Subject, Did, Salary)
Exam List the name of students with their department name and SPI of all student
ple belong to “CE” department.
Answ ∏ Sname, Dname, (σDname=‘CE’ (Student (Department
er SPI Academic)))
Exam Display the name of students with their project name whose
ple guide is “A. J. Shah”.
Answ ∏ Sname, (σFname=‘A.J.Shah’ (Student (Guide
er Pname Faculty)))
33
Relational Algebra
Operations
Outer Join
Section - 3.5
Outer Join
In natural join some records are missing, if we want that missing
records than we have to use outer join.
Three types of
Outer Join Sym
Sr. Outer Join
1 Left Outer Join bol
2 Right Outer Join
3 Full Outer Join
35
Left Outer Join
Symbol:
Notation: Relation-1 (R1) Relation-2 (R2) OR Algebra-1 Algebra-2
Operation:
Display all the tuples of the left relation even through there is no matching tuple
in the right relation.
For such kind of tuples having no matching, the attributes of right relation will be
padded with NULL in resultant relation.
Outp
ut
Roll Nam
SPI
No e
101 Raj 8
102 Meet NUL
L
103 NUL 9 41
Relational Algebra
Operations
Set Operators
Section - 3.6
Set Operators
Set operators combine the results of two or more queries into a
single result.
Exerci Is there any difference in the output if we swap the tables in Intersection.
se (Employee) ∩ (Customer).
47
Minus/ Set difference Operator
Symbol: −
Notation: Relation-1 (R1) − Relation-2 (R2) OR Algebra-1 − Algebra-2
Operation:
It displays all the tuples/records belonging to the first relation (left relation) but not in
the second relation (right relation).
Exam Perform Set difference between Customer Answ (Customer) −
ple and Employee. er (Employee)
Custo Emplo Outp
mer yee ut
Name Name Name
Raju Meet Raju
Suresh Suresh
Meet Manoj
Exerci Is there any difference in the output if we swap the tables in Set difference.
se (Employee) − (Customer).
48
Union Operators Example
49
Intersect/ Intersection Operators Example
50
Minus/ Set difference Operators Example
51
Minus/ Set difference Operators Example
52
Set Operators [Exercise]
Exerci What is the output of following relational algebra for the below
se mentioned tables:
Custo Emplo
mer
I Nam Balan yee
I Nam De Sala
D e ce D e pt ry
1 Raju 10000 2 Sures CE 8000
h
2 Sures 20000
h 3 Mano ME 9000
j
Algebr ∏ ID, Name(Customer) U ∏ ID, Name
a-1 (Employee)
Algebr ∏ ID, Name, Balance (Customer) U ∏ ID, Name, Salary
a-2 (Employee)
Algebr ∏ ID, Name(Customer) ∩ ∏ ID, Name
a-3 (Employee)
Algebr ∏ ID, Name, Balance (Customer) ∩ ∏ ID, Name, Salary
a-4 (Employee)
53
Set Operators [Exercise]
Exerci What is the output of following relational algebra for the below
se mentioned tables:
Custo Emplo
mer
I Nam Balan yee
I Nam De Sala
D e ce D e pt ry
1 Raju 10000 2 Sures CE 8000
h
2 Sures 20000
h 3 Mano ME 9000
j
Algebr ∏ ID, Name(Customer) − ∏ ID, Name
a-1 (Employee)
Algebr ∏ ID, Name, Balance (Customer) − ∏ ID, Name, Salary
a-2 (Employee)
Algebr ∏ ID, Name(Employee) − ∏ ID, Name
a-3 (Customer)
Algebr ∏ ID, Name, Balance (Employee) − ∏ ID, Name, Salary
a-4 (Customer)
54
Relational Algebra
Operations
Division Operator
Section - 3.7
Division Operator
Symbol: ÷ (Division)
Notation: Relation1 (R1) ÷ Relation2 (R2) OR Algebra1 ÷ Algebra2
Condition:
Attributes of relation2/algebra2 must be a proper subset of attributes of
relation1/algebra1.
Operation:
The output of the division operator will have attributes =
All attributes of relation1 – All attributes of relation2
The output of the division operator will have tuples =
Tuples in relation1, which are associated with the all tuples of relation2.
56
Division Operator Example
Exam Perform Division operation between Student Answ (Student) ÷
ple and Subject. er (Subject)
Stude Subje Outp
nt ct ut
Nam Subje Subjec Name
e ct t Rohit
Raj DBMS DBMS
Suresh
Raj DS DS
Meet DS DF
Meet DF
Rohit DBMS
Rohit DS
Rohit DF
Sures DBMS
h
Sures DF
h
Sures DS 57
Division Operator Example
A B B B B
Sn 1 2 3 4
PNo PNo PNo PNo PNo
o
P2 P2 P1 P2
S1 P1
P4 P2 P5
S1 P2
P4
S1 P3
Alge (A) ÷ Alge (A) ÷ Alge (A) ÷ Alge (A) ÷
S1 P4
bra (B1) bra (B2) bra (B3) bra (B4)
S2 P1 Outp Outp Outp Outp
ut ut ut ut
S2 P2 SNo SNo SNo SNo
S3 P2 S1 S1 S1
S4 P2 S2 S4
S4 P4 S3
S5 P4 S4
58
Division Operator Example
Exam List the name of students doing a project in all
ple technologies.
Stude Proje
nt
RN Nam Technol ct
TI Technol
o e ogy D ogy
10 Raj .NET 1 .NET
1
2 PHP
10 Raj PHP
1 3 Android
10 Meet .NET 4 iPhone
2
Answ ∏ Name, Technology (Student) ÷ ∏ Technology
10 Meet PHP er (Project)
2 Outp
10 Meet iPhone ut
Name
2
Meet
10 Meet Android
2
10 Rohit Android
3 59
Relational Algebra
Operations
Rename Operator
Section - 3.8
Rename Operator
Symbol: ρ (Rho)
Notation: ρ
A (X1,X2….Xn) (Relation)
Operation:
The rename operation is used to rename the output relation.
The result of rename operator are also relations with new name.
The original relation name can not be changed when we perform rename
operation on any relation.
How to use:
ρ x (E)
Returns a relation E under a new name X.
ρ A1, A2. …,An (E)
Returns a relation E with the attributes renamed to A1, A2, …., An.
ρ x(A1, A2. …,An) (E)
Returns a relation E under a new name X with the attributes renamed to A1,
61 A2,
Rename Operator Example
Exam Rename table Exam Rename
ple ple attributes
Stud Stud
ent ent
Rn Na CP
RN Na CP
o me I o me I
10 Raj 8 10 Raj 8
1 1
10 Meet 9 10 Meet 9
2 2
AlgeJay ρPerson
10 7 AlgeJay ρ(RollNo,
10 7 StudentName, SPI)
3
bra (Student) 3
bra (Student)
Perso Stud
n ent
Roll StudentN SP
RN Na CP
o me I No ame I
10 Raj 8 101 Raj 8
1
102 Meet 9
10 Meet 9
2 103 Jay 7
10 Jay 7 62
Rename Operator Example
Exam Rename table and Exam Rename particular
ple attributes both ple attributes
Stud Stud
ent
Rn Na CP ent
Rn Na CP
o me I o me I
10 Raj 8 10 Raj 8
1 1
10 Meet 9 10 Meet 9
2 2
AlgeJay ρPerson
10 7 (RollNo, StudentName) (∏ RNo, Name AlgeJay ρStudentName
10 7 / Name
3
bra (Student)) 3
bra (Student)
Perso Stud
n
Roll StudentN ent
Rn StudentN CP
No ame o ame I
101 Raj 10 Raj 8
102 Meet 1
10 Meet 9
103 Jay 2
63
Rename Operator Example
Exam Find out maximum CPI from Step- ρA (Student) X ρB
ple student table. 1 (Student)
Stud Outpu
ent
Rn Na CP t-1
A.Rn A.Na A.C B.Rn B.Na B.C
o me I o me PI o me PI
10 Raj 8 101 Raj 8 101 Raj 8
1
101 Raj 8 102 Meet 9
10 Meet 9
2 101 Raj 8 103 Jay 7
10 Jay
Step- 7σ
A.CPI<B.CPI (ρA (Student) X ρB 102 Meet 9 101 Raj 8
3
2 (Student)) 102 Meet 9 102 Meet 9
Outpu
t-2 102 Meet 9 103 Jay 7
A.Rn A.Na A.C B.Rn B.Na B.C
o me PI o me PI 103 Jay 7 101 Raj 8
101 Raj 8 102 Meet 9 103 Jay 7 102 Meet 9
103 Jay 7 101 Raj 8 103 Jay 7 103 Jay 7
103 Jay 7 102 Meet 9
64
Rename Operator Example
Exam Find out maximum CPI from
ple student table.
Stud
Step- ∏ A.CPI (σA.CPI<B.CPI (ρA (Student) X ρB
ent
Rn Na CP 3 (Student)))
o me I Outpu
10 Raj 8 t-3
A.CPI
1
8
10 Meet 9
2 7
10 Jay
Step- 7σ
A.CPI<B.CPI (ρA (Student) X ρB
3
2 (Student))
Outpu
t-2
A.Rn A.Na A.C B.Rn B.Na B.C
o me PI o me PI
101 Raj 8 102 Meet 9
103 Jay 7 101 Raj 8
103 Jay 7 102 Meet 9
65
Rename Operator Example
Exam Find out maximum CPI from
ple student table.
Stud
Step- ∏ A.CPI (σA.CPI<B.CPI (ρA (Student) X ρB
ent
Rn Na CP 3 (Student)))
o me I Outpu
10 Raj 8 t-3
A.CPI
1
8
10 Meet 9
2 7
10 Jay 7
Step-
3 ∏ CPI (Student) − ∏ A.CPI (σA.CPI<B.CPI (ρ A (Student) X
4
ρStud
B (Student))) Outpu Outpu
ent t-3 t
CPI A.CPI CPI
8 − 8 = 9
9 7
7
66
Relational Algebra
Operations
Aggregate Functions
Section - 3.9
Aggregate Functions
Symbol: g or G
Notation: g (Relation)
function-name(column), function-name(column), …, function-name(column)
Operation:
It takes a more than one value as input and returns a single value as output
(result).
Aggregate functions are:
Sum (It returns the sum (addition) of the values of a column.)
Max (It returns the maximum value for a column.)
Min (It returns the minimum value for a column.)
Avg (It returns the average of the values for a column.)
Count (It returns total number of values in a given column.)
68
Aggregate Functions Example
Stud
ent Exam Find out sum of CPI of all Outpu
Rn Bran Semes CP ple students. t
Name sum
o ch ter I
Answ g sum(CPI)
10 Rames CE 3 9 73
er (Student)
1 h
10 Mahes EC 3 8 Exam Find out maximum & Outpu
2 h ple minimum CPI. tma mi
10 Suresh ME 4 7 Answ g max(CPI), min(CPI) x n
3 er (Student) 9 7
10 Amit EE 4 8 Exam Count the number of Outpu
4 ple students. t
count
10 Anita CE 4 8 Answ g count(Rno)
5 9
er (Student)
10 Reeta ME 3 7
6
Exam Find out average of CPI of all Outpu
ple students. t
avg
Answ g avg(CPI)
10 Rohit EE 4 9
7 8.11
er (Student)
10 Chetan CE 3 8
8 69
Relational Algebra [Exercise]
Write down relational algebras for the following table:
Employee (person-name, street, city)
Works (person-name, company-name, salary)
Company (company-name, city)
Managers (person-name, manager-name)
Find the names of all employees who work for “TCS”.
Find the names and cities of residence of all employees who work for “Infosys”.
Find the names, street and city of residence of all employees who work for “ITC” and
earn more than $10,000 per annum.
Find the names of all employees in this database who live in the same city as the
company for which they work.
Find the names of all employees working in “TCS” who earn more than 25000 and
less than 40000.
Find the name of employee whose manager is “Ajay Patel” and salary is more than
50000.
Display the name of employee with street, city, company name, salary and manager
name staying in “Rajkot” and working in “Ahmedabad”.
Find maximum, minimum and average salary of all employee.
70
Open Source and
Commercial DBMS
Section - 4
Open Source and Commercial DBMS
Open Source Commercial DBMS
DBMS, which is available in the DBMS, which is available in the
market at free of cost. market at a certain price.
The code of open source DBMS The code of commercial DBMS
product can be viewed, shared or product can not be view, share or
modified
There arebychances
the community.
of malfunctioning modify by theiscommunity.
The security high and code is not
with code as source code is open. accessible to unauthorized person.
Examples: MySQL, MongoDB, SQLite Examples: Microsoft SQL Server, IBM
etc Db2 etc
72
Thank
You