SlideShare a Scribd company logo
1 of 48
PREPARED BY:
BHUMI AGHERA (130760107001)
MONIKA DUDHAT (130760107007)
RADHIKA TALAVIYA (130760107029)
RAJVI VAGHASIYA (130760107031)
Structure of relational databases
Primary key: Each row of a table is uniquely identified by a primary key
composed of one or more columns.
Candidate key: A column, or group of columns, that uniquely identifies a
row in a table is called a candidate key.
Foreign key: A column, or combination of columns, that matches the
primary key of another table is called a foreign key.
For each attribute there is a set of permitted values called Domain.
In other words we can say that A Domain D is a set of atomic
values.
Ex:
For our account table if we have 3 attributes as branch name,
account number and balance. Then for attribute branch name,
domain is set of all branch names.
Attributes & Domains
Let D1 denotes the set of all account numbers.
D2 denotes the set of all branch names.
D3 denotes the set of all balances.
So any row of account of table must consist of 3 tuple (V1, V2,V3)
Where,
V1 is an account number in the domain D1.
V2 is branch name in the domain D2.
V3 is a balance in the domain D3.
Therefore we can say account is a subset of D1×D2×D3.
 To generalize we can say that,a table of n attributes must be
subset of D1×D2×D3…×Dn-1×Dn
 We can say that a relation to be a subset of Cartesian product of a
list of domain which corresponds to our definition of table.
 The main construct for representing data in the relation model is
a relation.
 A relation consists of a relation schema and a relation instance.
 The relation instance is a table and relation schema describes the
column heads for the table.
 The schema specifies the relation name,the name of each field
and the domain of each field.
 An instance of a relation is a set of tuples can also be referred as
records, in which each tuple has the same number of fields as the
relation schema.
 Let us take an example of student relation.
The student table has following attributes
a) Sid: student id
b) Name: name of the student
c) Age: age of student
sid name age
S101 Rohit 20
S102 Parita 22
S103 sanjana 23
Attributes
Field
names
Tulpes
 Hence, A relational database is a collection of relations with
distinct relation names. The relational database schema is
the collection of schemas for the relations in the database.
Domain Constraint
In the schema, every attribute is declared to have a type integer, float,
date, Boolean, string, etc.
An insertion request can violate the domain constraint.
DBMS can check if insertion violates domain constraint and reject the
insertion.
Key Constraint and Constraint on Null Values
A key constraint is a statement that a certain minimal subset as the fields
of a relation is a unique identifier for a tuple.
A set of fields that uniquely identifies a tuple according to a key
constraint is called a candidate key for the relation.
Another constraint on attribute specifies whether null values are or are
not permitted.
E.g. if every student tuple must have a valid, non-null value for the name
attribute, the name of student is constrained to be NOT NULL.
Entity Integrity Constraint
A primary key must not contain a null value, else it may not be
possible to identify some tuples.
• For Example, if more than one tuple has a null value in its primary
key, we may not be able to distinguish them .
Referential Integrity and Foreign Keys
The condition for a foreign key given below, specify a referential integrity
constraint between two relation schemas R1 and R2.
A set of attributes Fk in relation schema R1 is a foreign key of R1 that
references relation R2 if it satisfies following 2 rules.
1. The attributes in Fk have the same domain, as the primary key attribute
Pk of R2, the attributes Fk are said to reference to the relation R2.
2. A value of Fk in a tuple t1 in the current state r1(R1) either occur as a
value of Pk for some tuple t2 in the r2(R2) or is null.
In this definition R1 is called the referencing relation and R2 is
the referenced relation.
Sid Name Age
S101 Swati 20
S102 Ruchita 20
S103 Ushma 19
S104 Jones 25
Cid Grade Studid
His.111 A S101
Maths121 B S102
Topology1 B S103
Sci.11 C S104
Foreign Key Primary Key
Student
(Referenced relation)
Enrolled
(Referencing Relation)
Relational algebra
It is one of the two formal query languages associated with the relational
model.
Six basic operators are as below:
1. Selection
2. Projection
3. Union
4. Intersection
5. Set difference
6. Cross product
7. Renaming
The operators take one or two relations as inputs and produce a new relation
as a result.
Sid Sname rating Age
22 Ritesh 7 45
31 Sonal 8 55
58 Uttam 10 35
Sid Sname rating Age
28 Swati 9 35
31 Sonal 8 55
44 Maulik 5 35
58 Uttam 10 35
Table S1
Table S2
Selection
The select operation selects tuples that satisfy a given predicate.
Notation: σc(r)
c is called the selection predicate.
c = <attribute> op <attribute> or <constant>
where, op is one of: <,<=,=,!=,>,>=.
Ex:
σ rating > 8(S2)
The selection criteria is rating > 8.
The result is shown in the below table.
Sid Sname rating Age
28 Swati 9 35
58 Uttam 10 35
Projection
The project operation is a unary operation that returns its argument
relation, with certain attributes left out.
Notation: П A1,A2…Ak (r)
where A1, A2 are attribute names and r is a relation name.
The result is defined as the relation of k columns obtained by erasing
the columns that are not listed.
Duplicate rows removed from result.
Ex:
П sname,rating(S2)
The result is shown in below table:
Sname rating
Swati 9
Sonal 8
Maulik 5
Uttam 10
Now, using selection &projection we can compute the names
and rating of highly rated sailor as:
П sname,rating(σ rating > 8(S2))
The result is obtained by applying the selection to S2 and then
applying the projection, which is as shown in below table.
Sname rating
Swati 9
Uttam 10
Union
In order to perform the union operation, both operand relations must be
union-compatible i.e. they must have same number of columns drawn
from the same domain.
R U S returns a relation instance containing all tuples that occur in either
relation instance R or relation instance S(or both).
 Ex:
S1 U S2.
The union of S1 & S2. i.e.S1 U S2 would result in:
Sid Sname rating Age
22 Ritesh 7 45
31 Ritesh 8 55
58 Uttam 10 30
28 Swati 9 35
44 Maulik 5 35
Intersection
R ∩ S returns a relation instance containing all tuples that occur both
in R and S.
The relation R and S must be union compatible and the schema of
the result is defined to be identical to the schema of R.
 Ex:
S1 ∩ S2.
Sid Sname rating Age
31 Ritesh 8 55
58 Uttam 10 30
Set difference
R – S returns a relation instance containing all tuples that occur in R
but not in S.
Ex:
S1 – S2
The set difference S1 – S2 is as shown in table.
Sid Sname rating Age
22 Ritesh 7 45
Cross product
R × S returns a relation instance whose schema contains all the field of
R followed by all the fields of S.
The cross product operation is also known as the Cartesian product.
Ex:
The cross product between two instance S1 and R1 which are as
shown in the next table:
Sid Sname rating Age
22 Ritesh 7 45
31 Sonal 8 55
58 Uttam 10 35
Table S1
Table R1
Sid Bid Day
22 101 10/10/96
58 103 11/12/96
R1 and S1 both have a field named sid .The cross product between
them is as shown in below table.
Sid Sname Rating Age Sid Bid Day
22 Ritesh 7 45 22 101 10/10/96
22 Ritesh 7 45 58 103 11/12/96
31 Sonal 8 55 22 101 10/10/96
31 Sonal 8 55 58 103 11/12/96
58 Uttam 10 35 22 101 10/10/96
58 Uttam 10 35 58 103 11/12/96
Renaming
The results of relational-algebra expressions do not have a
name that we can use to refer to them. Renaming is useful to
be able to give them names.
The rename operator is denoted by the lowercase Greek letter
rho (ρ).
Given a relational-algebra expression E, the expression ρx(E)
returns the result of expression E under the name x.
Join
Join operation is used to combine information from two or more
relations.
A join can be defined as a cross product followed by selections
and projections. The result of a cross product is much larger than
the result of a join.
There are several kind of joins:
• Condition join
• Equijoin
• Natural join
 Defined as a cross-product followed by a selection:
R ⋈c S = σc(R  S) where c is the condition.
 Example:
Given the sample relational instances S1 and R1
The condition join S1 ⋈S1.sid<R1.sid R1 yields
Sid Sname Rating Age
22 Dustin 7 45.0
31 Lubber 8 55.5
58 Rusty 10 35.0
Sid Bid Day
22 101 10/10/96
58 103 11/12/96
Condition join
(sid) Sname Rating Age (sid) Bid Day
22 Dustin 7 45.0 58 103 11/12/96
31 Lubber 8 55.5 58 103 11/12/96
Equijoin
Special case of the condition join where the join condition consists solely
of equalities between two fields in R and S connected by the logical AND
operator (∧).
Example: Given the two sample relational instances S1 and R1
Sid Sname Rating Age
22 Dustin 7 45.0
31 Lubber 8 55.5
58 Rusty 10 35.0
Sid Bid Day
22 101 10/10/96
58 103 11/12/96
The operator S1 ⋈R.sid=S.sid R1 yields
Sid Sname Rating Age Bid Day
22 Dustin 7 45.0 101 10/10/96
58 Rusty 10 35.0 103 11/12/96
Natural join
Special case of equijoin where equalities are implicitly specified on
all fields having the same name in R and S.
The condition c is now left out, so that the “bow tie” operator by
itself signifies a natural join.
N. B. If the two relations have no attributes in common, the natural
join is simply the cross-product.
Division
The division operator is used for queries which involve the ‘all’ qualifier.
such as “Find the names of sailors who have reserved all boats”..
Consider two relation instances A and B in which A has two fields x and y
and B has just one field y , with the same domain as in A.
The division operator A/B is defined as the set of all x values that for every
y value in B, there is a tuple <x,y> in A.
An analogy with integer division may also help to understand division. For
integers A and B, A/B is the largest integer Q such that Q * B ≤ A.
For relation instances A and B , A/B in the largest relation instance Q such
that Q × B ⊆ A.
S# P#
S1 P1
S1 P2
S1 P3
S1 P4
S2 P1
S2 P2
S3 P2
S4 P2
S4 P4
P#
P2
P#
P2
P4
P#
P1
P2
P4
S#
S1
S2
S3
S4
S#
S1
S4
S#
S1
 The relation A can be thought of as a relation listing parts supplied by
suppliers and of the B relations as listing parts. A/Bi computes
suppliers who supply all parts listed in relation instance Bi.
Generalized projection
The generalized projection extends the projection operation by allowing
arithmetic functions to be used in the projection list.
The generalized projection has the form
Where, E is any relational algebra expression. each of F1,
F2,…, Fn is an arithmetic expression involving constants and
attributes in the schema of E.
1 2, ,..., ( )nF F F E
Customer name Limit Credit balance
Swati 2000 1750
Ruchita 1500 1500
Manthan 6000 700
Ushma 2000 400
Customer name Result
Swati 250
Ruchita 5300
Manthan 1600
Ushma 0
 Let us consider the following relation
 Suppose if we want to find out how much each person can spend,
we can write: ,lim ( inf)customer name it creditbalance credit  
Aggregate function
Aggregate function takes a collection of values and returns a single value
as a result.
Aggregate functions are sum, avg, count, min and max.
To understand aggregate function , lets us consider the pt-works relation
for part time employees.
Employee-name Branch-name Salary
Swati Pune 1500
Ruchita Pune 1300
Manthan Mumbai 5300
Ushma Mumbai 1500
Arpita Delhi 2500
Sameer Delhi 1300
Branch name Salary
Delhi 3800
Mumbai 6800
Pune 2800
 To find out the total sum of salaries of all the part
employees in the bank. The expression would be
Outer join
This operation is an extension of the join operation of deal with missing
information.
These are three types of out joins:
a) Left outer join, denoted by
b) Right outer join, denoted by
c) Full outer join, denoted by
Consider the employee and ft-works relations.
Employee name Street City
Swati Salisbury park Pune
Ruchita Kothrud Mumbai
Ushma Sion Delhi
Arpit Mint street Chennai
Employee name Branch name Salary
Swati ABC 1500
Ruchita XYZ 1300
Ushma PQR 5300
Arpit WBC 1500
Employee ⋈ ft-works
Employee-name Street City Branch-name Salary
Swati Salisbury park Pune ABC 1500
Ruchita Kothrud Mumbai XYZ 1300
Ushma Sion Delhi PQR 5300
Employee-name Street City Branch-name Salary
Swati Salisbury park Pune ABC 1500
Ruchita Kothrud Mumbai XYZ 1300
Ushma Sion Delhi PQR 5300
Arpit Mint street Chennai Null Null
Left outer join takes all tuples in the left relation that didn’t match
with any tuple in right relation, pads the tuples with null values for all
other attributes from the right relation.
 The right outer join is symmetric with left outer join. It pads
tuples from the right relation that did not match any from left
relation with nulls and adds them to the result of natural join.
Employee-name Street City Branch-name Salary
Swati Salisbury park Pune ABC 1500
Ruchita Kothrud Mumbai XYZ 1300
Ushma Sion Delhi PQR 5300
Arpita Null Null WBC 1500
Employee-name Street City Branch-name Salary
Swati Salisbury park Pune ABC 1500
Ruchita Kothrud Mumbai XYZ 1300
Ushma Sion Delhi PQR 5300
Arpit Mint street Chennai Null Null
Arpita Null Null WBC 1500
 The full outer join does both of these operations, padding tuples
from the left relation that didn’t match any from the relation, as
well as tuples from the right relation that didn’t match any from the
left relation.
Example
sid Sname Rating Age
22 Swati 7 45
29 Ushma 1 33
31 Ruchita 8 55.5
32 Manthan 8 25.5
58 Amit 10 35
64 Arpit 3 63.5
Sid Bid Day
22 101 10/10/98
22 102 10/10/98
22 103 10/8/98
31 101 11/10/98
31 102 11/6/98
31 103 11/2/98
64 101 9/5/98
64 102 9/8/98
64 103 9/8/98
Bid bname Color
101 Marine Red
102 Clipper Green
103 Interlake Blue
a) Find the names of sailors who have reserved boats 103.
sname((σbid=103 Reserves) ⋈ Sailors)
b) Find the names of sailors who have reserved a red boat.
sname((σcolor=‘red’Boats) ⋈ Reserves ⋈ Sailors)
c) Find the names of sailors who have reserved at least one boat.
sname(Sailors ⋈ Reserves)
d) Find the names of sailors who have reserved a red or green boat.
(Tempboats, (σcolor=‘red’Boats) ∪ (σcolor=‘green’Boats))
sname(Tempboats ⋈ Reserves ⋈ Sailors)
e) Find the names of sailors who have reserved all boats called
Interlake.
(Tempsids, (sid,bidReserves)/(bid(σbname=‘Interlake’Boats)))
sname(Tempsids ⋈ Sailors)
f) Find the sids of sailors with age over 20 who have not
reserved a red boat.
sid(σage>20Sailors) - sid((σcolor=‘red’Boats) ⋈ Reserves ⋈ Sailors)
g) Find the colors of boats reserved by Lubber.
color((σsname=‘Lubber’Sailors)Sailors ⋈ Reserves ⋈ Boats)

More Related Content

What's hot

My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebraRushdi Shams
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra IntroductionMd. Afif Al Mamun
 
Relational algebra (basics)
Relational algebra (basics)Relational algebra (basics)
Relational algebra (basics)usama nizam
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Prosanta Ghosh
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systemsjakodongo
 
DBMS : Relational Algebra
DBMS : Relational Algebra DBMS : Relational Algebra
DBMS : Relational Algebra Sridhar Baithi
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculusVaibhav Kathuria
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational AlgebraAmin Omi
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptxRUpaliLohar
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Eddyzulham Mahluzydde
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra OperationsA. S. M. Shafi
 
7 relational database design algorithms and further dependencies
7 relational database design algorithms and further dependencies7 relational database design algorithms and further dependencies
7 relational database design algorithms and further dependenciesKumar
 

What's hot (18)

Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Relational+algebra (1)
Relational+algebra (1)Relational+algebra (1)
Relational+algebra (1)
 
My slide relational algebra
My slide  relational algebraMy slide  relational algebra
My slide relational algebra
 
Relational Algebra Introduction
Relational Algebra IntroductionRelational Algebra Introduction
Relational Algebra Introduction
 
Relational algebra (basics)
Relational algebra (basics)Relational algebra (basics)
Relational algebra (basics)
 
Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013Dbms ii mca-ch4-relational model-2013
Dbms ii mca-ch4-relational model-2013
 
Relational Algebra-Database Systems
Relational Algebra-Database SystemsRelational Algebra-Database Systems
Relational Algebra-Database Systems
 
Relational algebra
Relational algebraRelational algebra
Relational algebra
 
DBMS : Relational Algebra
DBMS : Relational Algebra DBMS : Relational Algebra
DBMS : Relational Algebra
 
Relational algebra calculus
Relational algebra  calculusRelational algebra  calculus
Relational algebra calculus
 
Relational Algebra
Relational AlgebraRelational Algebra
Relational Algebra
 
Unit04 dbms
Unit04 dbmsUnit04 dbms
Unit04 dbms
 
Relational algebra.pptx
Relational algebra.pptxRelational algebra.pptx
Relational algebra.pptx
 
Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2Chapter 2 Relational Data Model-part 2
Chapter 2 Relational Data Model-part 2
 
Lec02
Lec02Lec02
Lec02
 
1643 y є r relational calculus-1
1643 y є r  relational calculus-11643 y є r  relational calculus-1
1643 y є r relational calculus-1
 
Additional Relational Algebra Operations
Additional Relational Algebra OperationsAdditional Relational Algebra Operations
Additional Relational Algebra Operations
 
7 relational database design algorithms and further dependencies
7 relational database design algorithms and further dependencies7 relational database design algorithms and further dependencies
7 relational database design algorithms and further dependencies
 

Similar to RDB Structure, Constraints & Relational Algebra

Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Raj vardhan
 
Chapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfChapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfTamiratDejene1
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptMisganawAbeje1
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdfKavinilaa
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMSkoolkampus
 
Relational Algebra and Calculus.ppt
Relational Algebra and Calculus.pptRelational Algebra and Calculus.ppt
Relational Algebra and Calculus.pptAnkush138
 
Relational Model
Relational ModelRelational Model
Relational ModelSiti Ismail
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfajajkhan16
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptxThangamaniR3
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model IntroductionNishant Munjal
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relationalJafar Nesargi
 

Similar to RDB Structure, Constraints & Relational Algebra (20)

Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
Relational Algebra Ch6 (Navathe 4th edition)/ Ch7 (Navathe 3rd edition)
 
Chapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdfChapter – 5 Relational Algebra.pdf
Chapter – 5 Relational Algebra.pdf
 
chapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.pptchapter 5-Relational Algebra and calculus.ppt
chapter 5-Relational Algebra and calculus.ppt
 
uniT 4 (1).pptx
uniT 4 (1).pptxuniT 4 (1).pptx
uniT 4 (1).pptx
 
Ra Revision
Ra RevisionRa Revision
Ra Revision
 
1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf1695304562_RELATIONAL_ALGEBRA.pdf
1695304562_RELATIONAL_ALGEBRA.pdf
 
Relational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdfRelational Algebra-23-04-2023.pdf
Relational Algebra-23-04-2023.pdf
 
4. SQL in DBMS
4. SQL in DBMS4. SQL in DBMS
4. SQL in DBMS
 
Relational Algebra and Calculus.ppt
Relational Algebra and Calculus.pptRelational Algebra and Calculus.ppt
Relational Algebra and Calculus.ppt
 
DBMS Unit-2.pdf
DBMS Unit-2.pdfDBMS Unit-2.pdf
DBMS Unit-2.pdf
 
Relational Model
Relational ModelRelational Model
Relational Model
 
354 ch6
354 ch6354 ch6
354 ch6
 
Chapter6
Chapter6Chapter6
Chapter6
 
Unit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdfUnit-II DBMS presentation for students.pdf
Unit-II DBMS presentation for students.pdf
 
Cs501 rel algebra
Cs501 rel algebraCs501 rel algebra
Cs501 rel algebra
 
RDBMS
RDBMSRDBMS
RDBMS
 
relational model.pptx
relational model.pptxrelational model.pptx
relational model.pptx
 
Relational Data Model Introduction
Relational Data Model IntroductionRelational Data Model Introduction
Relational Data Model Introduction
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 
Chapter 6 relational data model and relational
Chapter  6  relational data model and relationalChapter  6  relational data model and relational
Chapter 6 relational data model and relational
 

More from Radhika Talaviya

General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)Radhika Talaviya
 
screen speculo - Miracast android Project
screen speculo - Miracast android Projectscreen speculo - Miracast android Project
screen speculo - Miracast android ProjectRadhika Talaviya
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING Radhika Talaviya
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System ProgrammingRadhika Talaviya
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaRadhika Talaviya
 
Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters Radhika Talaviya
 
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...Radhika Talaviya
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisRadhika Talaviya
 
Level, Role, and Skill manager
Level, Role, and Skill  managerLevel, Role, and Skill  manager
Level, Role, and Skill managerRadhika Talaviya
 
Global environmental essue
Global environmental essueGlobal environmental essue
Global environmental essueRadhika Talaviya
 

More from Radhika Talaviya (16)

General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)General Packet Radio Service(GPRS)
General Packet Radio Service(GPRS)
 
The Phases of a Compiler
The Phases of a CompilerThe Phases of a Compiler
The Phases of a Compiler
 
screen speculo - Miracast android Project
screen speculo - Miracast android Projectscreen speculo - Miracast android Project
screen speculo - Miracast android Project
 
MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING MICROPROCESSOR AND INTERFACING
MICROPROCESSOR AND INTERFACING
 
Assembler - System Programming
Assembler - System ProgrammingAssembler - System Programming
Assembler - System Programming
 
Classes, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with JavaClasses, Objects and Method - Object Oriented Programming with Java
Classes, Objects and Method - Object Oriented Programming with Java
 
Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters Cyber Security - Firewall and Packet Filters
Cyber Security - Firewall and Packet Filters
 
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
Shopping At Mall without standing in Queue for Bill Payment by Scanning Bar c...
 
Analysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysisAnalysis and Design of Algorithms -Sorting Algorithms and analysis
Analysis and Design of Algorithms -Sorting Algorithms and analysis
 
Computer Organization
Computer Organization Computer Organization
Computer Organization
 
Stack
StackStack
Stack
 
Level, Role, and Skill manager
Level, Role, and Skill  managerLevel, Role, and Skill  manager
Level, Role, and Skill manager
 
Global environmental essue
Global environmental essueGlobal environmental essue
Global environmental essue
 
Reflection of girls life
Reflection of girls lifeReflection of girls life
Reflection of girls life
 
Nanophysics
NanophysicsNanophysics
Nanophysics
 
I'm ok you're ok
I'm ok you're okI'm ok you're ok
I'm ok you're ok
 

Recently uploaded

power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and usesDevarapalliHaritha
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...srsj9000
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfAsst.prof M.Gokilavani
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)dollysharma2066
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfme23b1001
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxvipinkmenon1
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2RajaP95
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx959SahilShah
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girlsssuser7cb4ff
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AIabhishek36461
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 

Recently uploaded (20)

🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
🔝9953056974🔝!!-YOUNG call girls in Rajendra Nagar Escort rvice Shot 2000 nigh...
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Serviceyoung call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
young call girls in Rajiv Chowk🔝 9953056974 🔝 Delhi escort Service
 
power system scada applications and uses
power system scada applications and usespower system scada applications and uses
power system scada applications and uses
 
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
Gfe Mayur Vihar Call Girls Service WhatsApp -> 9999965857 Available 24x7 ^ De...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdfCCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
CCS355 Neural Network & Deep Learning UNIT III notes and Question bank .pdf
 
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
Call Us ≽ 8377877756 ≼ Call Girls In Shastri Nagar (Delhi)
 
Electronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdfElectronically Controlled suspensions system .pdf
Electronically Controlled suspensions system .pdf
 
Introduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptxIntroduction to Microprocesso programming and interfacing.pptx
Introduction to Microprocesso programming and interfacing.pptx
 
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2HARMONY IN THE HUMAN BEING - Unit-II UHV-2
HARMONY IN THE HUMAN BEING - Unit-II UHV-2
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Application of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptxApplication of Residue Theorem to evaluate real integrations.pptx
Application of Residue Theorem to evaluate real integrations.pptx
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
Call Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call GirlsCall Girls Narol 7397865700 Independent Call Girls
Call Girls Narol 7397865700 Independent Call Girls
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 
Past, Present and Future of Generative AI
Past, Present and Future of Generative AIPast, Present and Future of Generative AI
Past, Present and Future of Generative AI
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 

RDB Structure, Constraints & Relational Algebra

  • 1. PREPARED BY: BHUMI AGHERA (130760107001) MONIKA DUDHAT (130760107007) RADHIKA TALAVIYA (130760107029) RAJVI VAGHASIYA (130760107031)
  • 2. Structure of relational databases Primary key: Each row of a table is uniquely identified by a primary key composed of one or more columns. Candidate key: A column, or group of columns, that uniquely identifies a row in a table is called a candidate key. Foreign key: A column, or combination of columns, that matches the primary key of another table is called a foreign key.
  • 3. For each attribute there is a set of permitted values called Domain. In other words we can say that A Domain D is a set of atomic values. Ex: For our account table if we have 3 attributes as branch name, account number and balance. Then for attribute branch name, domain is set of all branch names. Attributes & Domains
  • 4. Let D1 denotes the set of all account numbers. D2 denotes the set of all branch names. D3 denotes the set of all balances. So any row of account of table must consist of 3 tuple (V1, V2,V3) Where, V1 is an account number in the domain D1. V2 is branch name in the domain D2. V3 is a balance in the domain D3. Therefore we can say account is a subset of D1×D2×D3.
  • 5.  To generalize we can say that,a table of n attributes must be subset of D1×D2×D3…×Dn-1×Dn  We can say that a relation to be a subset of Cartesian product of a list of domain which corresponds to our definition of table.  The main construct for representing data in the relation model is a relation.  A relation consists of a relation schema and a relation instance.  The relation instance is a table and relation schema describes the column heads for the table.  The schema specifies the relation name,the name of each field and the domain of each field.
  • 6.  An instance of a relation is a set of tuples can also be referred as records, in which each tuple has the same number of fields as the relation schema.  Let us take an example of student relation. The student table has following attributes a) Sid: student id b) Name: name of the student c) Age: age of student
  • 7. sid name age S101 Rohit 20 S102 Parita 22 S103 sanjana 23 Attributes Field names Tulpes  Hence, A relational database is a collection of relations with distinct relation names. The relational database schema is the collection of schemas for the relations in the database.
  • 8. Domain Constraint In the schema, every attribute is declared to have a type integer, float, date, Boolean, string, etc. An insertion request can violate the domain constraint. DBMS can check if insertion violates domain constraint and reject the insertion.
  • 9. Key Constraint and Constraint on Null Values A key constraint is a statement that a certain minimal subset as the fields of a relation is a unique identifier for a tuple. A set of fields that uniquely identifies a tuple according to a key constraint is called a candidate key for the relation. Another constraint on attribute specifies whether null values are or are not permitted. E.g. if every student tuple must have a valid, non-null value for the name attribute, the name of student is constrained to be NOT NULL.
  • 10. Entity Integrity Constraint A primary key must not contain a null value, else it may not be possible to identify some tuples. • For Example, if more than one tuple has a null value in its primary key, we may not be able to distinguish them .
  • 11. Referential Integrity and Foreign Keys The condition for a foreign key given below, specify a referential integrity constraint between two relation schemas R1 and R2. A set of attributes Fk in relation schema R1 is a foreign key of R1 that references relation R2 if it satisfies following 2 rules. 1. The attributes in Fk have the same domain, as the primary key attribute Pk of R2, the attributes Fk are said to reference to the relation R2. 2. A value of Fk in a tuple t1 in the current state r1(R1) either occur as a value of Pk for some tuple t2 in the r2(R2) or is null.
  • 12. In this definition R1 is called the referencing relation and R2 is the referenced relation. Sid Name Age S101 Swati 20 S102 Ruchita 20 S103 Ushma 19 S104 Jones 25 Cid Grade Studid His.111 A S101 Maths121 B S102 Topology1 B S103 Sci.11 C S104 Foreign Key Primary Key Student (Referenced relation) Enrolled (Referencing Relation)
  • 13. Relational algebra It is one of the two formal query languages associated with the relational model. Six basic operators are as below: 1. Selection 2. Projection 3. Union 4. Intersection 5. Set difference 6. Cross product 7. Renaming The operators take one or two relations as inputs and produce a new relation as a result.
  • 14. Sid Sname rating Age 22 Ritesh 7 45 31 Sonal 8 55 58 Uttam 10 35 Sid Sname rating Age 28 Swati 9 35 31 Sonal 8 55 44 Maulik 5 35 58 Uttam 10 35 Table S1 Table S2
  • 15. Selection The select operation selects tuples that satisfy a given predicate. Notation: σc(r) c is called the selection predicate. c = <attribute> op <attribute> or <constant> where, op is one of: <,<=,=,!=,>,>=. Ex: σ rating > 8(S2)
  • 16. The selection criteria is rating > 8. The result is shown in the below table. Sid Sname rating Age 28 Swati 9 35 58 Uttam 10 35
  • 17. Projection The project operation is a unary operation that returns its argument relation, with certain attributes left out. Notation: П A1,A2…Ak (r) where A1, A2 are attribute names and r is a relation name. The result is defined as the relation of k columns obtained by erasing the columns that are not listed. Duplicate rows removed from result. Ex: П sname,rating(S2)
  • 18. The result is shown in below table: Sname rating Swati 9 Sonal 8 Maulik 5 Uttam 10
  • 19. Now, using selection &projection we can compute the names and rating of highly rated sailor as: П sname,rating(σ rating > 8(S2)) The result is obtained by applying the selection to S2 and then applying the projection, which is as shown in below table. Sname rating Swati 9 Uttam 10
  • 20. Union In order to perform the union operation, both operand relations must be union-compatible i.e. they must have same number of columns drawn from the same domain. R U S returns a relation instance containing all tuples that occur in either relation instance R or relation instance S(or both).  Ex: S1 U S2.
  • 21. The union of S1 & S2. i.e.S1 U S2 would result in: Sid Sname rating Age 22 Ritesh 7 45 31 Ritesh 8 55 58 Uttam 10 30 28 Swati 9 35 44 Maulik 5 35
  • 22. Intersection R ∩ S returns a relation instance containing all tuples that occur both in R and S. The relation R and S must be union compatible and the schema of the result is defined to be identical to the schema of R.  Ex: S1 ∩ S2. Sid Sname rating Age 31 Ritesh 8 55 58 Uttam 10 30
  • 23. Set difference R – S returns a relation instance containing all tuples that occur in R but not in S. Ex: S1 – S2 The set difference S1 – S2 is as shown in table. Sid Sname rating Age 22 Ritesh 7 45
  • 24. Cross product R × S returns a relation instance whose schema contains all the field of R followed by all the fields of S. The cross product operation is also known as the Cartesian product. Ex: The cross product between two instance S1 and R1 which are as shown in the next table:
  • 25. Sid Sname rating Age 22 Ritesh 7 45 31 Sonal 8 55 58 Uttam 10 35 Table S1 Table R1 Sid Bid Day 22 101 10/10/96 58 103 11/12/96
  • 26. R1 and S1 both have a field named sid .The cross product between them is as shown in below table. Sid Sname Rating Age Sid Bid Day 22 Ritesh 7 45 22 101 10/10/96 22 Ritesh 7 45 58 103 11/12/96 31 Sonal 8 55 22 101 10/10/96 31 Sonal 8 55 58 103 11/12/96 58 Uttam 10 35 22 101 10/10/96 58 Uttam 10 35 58 103 11/12/96
  • 27. Renaming The results of relational-algebra expressions do not have a name that we can use to refer to them. Renaming is useful to be able to give them names. The rename operator is denoted by the lowercase Greek letter rho (ρ). Given a relational-algebra expression E, the expression ρx(E) returns the result of expression E under the name x.
  • 28. Join Join operation is used to combine information from two or more relations. A join can be defined as a cross product followed by selections and projections. The result of a cross product is much larger than the result of a join. There are several kind of joins: • Condition join • Equijoin • Natural join
  • 29.  Defined as a cross-product followed by a selection: R ⋈c S = σc(R  S) where c is the condition.  Example: Given the sample relational instances S1 and R1 The condition join S1 ⋈S1.sid<R1.sid R1 yields Sid Sname Rating Age 22 Dustin 7 45.0 31 Lubber 8 55.5 58 Rusty 10 35.0 Sid Bid Day 22 101 10/10/96 58 103 11/12/96 Condition join (sid) Sname Rating Age (sid) Bid Day 22 Dustin 7 45.0 58 103 11/12/96 31 Lubber 8 55.5 58 103 11/12/96
  • 30. Equijoin Special case of the condition join where the join condition consists solely of equalities between two fields in R and S connected by the logical AND operator (∧). Example: Given the two sample relational instances S1 and R1 Sid Sname Rating Age 22 Dustin 7 45.0 31 Lubber 8 55.5 58 Rusty 10 35.0 Sid Bid Day 22 101 10/10/96 58 103 11/12/96
  • 31. The operator S1 ⋈R.sid=S.sid R1 yields Sid Sname Rating Age Bid Day 22 Dustin 7 45.0 101 10/10/96 58 Rusty 10 35.0 103 11/12/96
  • 32. Natural join Special case of equijoin where equalities are implicitly specified on all fields having the same name in R and S. The condition c is now left out, so that the “bow tie” operator by itself signifies a natural join. N. B. If the two relations have no attributes in common, the natural join is simply the cross-product.
  • 33. Division The division operator is used for queries which involve the ‘all’ qualifier. such as “Find the names of sailors who have reserved all boats”.. Consider two relation instances A and B in which A has two fields x and y and B has just one field y , with the same domain as in A. The division operator A/B is defined as the set of all x values that for every y value in B, there is a tuple <x,y> in A. An analogy with integer division may also help to understand division. For integers A and B, A/B is the largest integer Q such that Q * B ≤ A. For relation instances A and B , A/B in the largest relation instance Q such that Q × B ⊆ A.
  • 34. S# P# S1 P1 S1 P2 S1 P3 S1 P4 S2 P1 S2 P2 S3 P2 S4 P2 S4 P4 P# P2 P# P2 P4 P# P1 P2 P4 S# S1 S2 S3 S4 S# S1 S4 S# S1  The relation A can be thought of as a relation listing parts supplied by suppliers and of the B relations as listing parts. A/Bi computes suppliers who supply all parts listed in relation instance Bi.
  • 35. Generalized projection The generalized projection extends the projection operation by allowing arithmetic functions to be used in the projection list. The generalized projection has the form Where, E is any relational algebra expression. each of F1, F2,…, Fn is an arithmetic expression involving constants and attributes in the schema of E. 1 2, ,..., ( )nF F F E
  • 36. Customer name Limit Credit balance Swati 2000 1750 Ruchita 1500 1500 Manthan 6000 700 Ushma 2000 400 Customer name Result Swati 250 Ruchita 5300 Manthan 1600 Ushma 0  Let us consider the following relation  Suppose if we want to find out how much each person can spend, we can write: ,lim ( inf)customer name it creditbalance credit  
  • 37. Aggregate function Aggregate function takes a collection of values and returns a single value as a result. Aggregate functions are sum, avg, count, min and max. To understand aggregate function , lets us consider the pt-works relation for part time employees. Employee-name Branch-name Salary Swati Pune 1500 Ruchita Pune 1300 Manthan Mumbai 5300 Ushma Mumbai 1500 Arpita Delhi 2500 Sameer Delhi 1300
  • 38. Branch name Salary Delhi 3800 Mumbai 6800 Pune 2800  To find out the total sum of salaries of all the part employees in the bank. The expression would be
  • 39. Outer join This operation is an extension of the join operation of deal with missing information. These are three types of out joins: a) Left outer join, denoted by b) Right outer join, denoted by c) Full outer join, denoted by
  • 40. Consider the employee and ft-works relations. Employee name Street City Swati Salisbury park Pune Ruchita Kothrud Mumbai Ushma Sion Delhi Arpit Mint street Chennai Employee name Branch name Salary Swati ABC 1500 Ruchita XYZ 1300 Ushma PQR 5300 Arpit WBC 1500
  • 41. Employee ⋈ ft-works Employee-name Street City Branch-name Salary Swati Salisbury park Pune ABC 1500 Ruchita Kothrud Mumbai XYZ 1300 Ushma Sion Delhi PQR 5300
  • 42. Employee-name Street City Branch-name Salary Swati Salisbury park Pune ABC 1500 Ruchita Kothrud Mumbai XYZ 1300 Ushma Sion Delhi PQR 5300 Arpit Mint street Chennai Null Null Left outer join takes all tuples in the left relation that didn’t match with any tuple in right relation, pads the tuples with null values for all other attributes from the right relation.
  • 43.  The right outer join is symmetric with left outer join. It pads tuples from the right relation that did not match any from left relation with nulls and adds them to the result of natural join. Employee-name Street City Branch-name Salary Swati Salisbury park Pune ABC 1500 Ruchita Kothrud Mumbai XYZ 1300 Ushma Sion Delhi PQR 5300 Arpita Null Null WBC 1500
  • 44. Employee-name Street City Branch-name Salary Swati Salisbury park Pune ABC 1500 Ruchita Kothrud Mumbai XYZ 1300 Ushma Sion Delhi PQR 5300 Arpit Mint street Chennai Null Null Arpita Null Null WBC 1500  The full outer join does both of these operations, padding tuples from the left relation that didn’t match any from the relation, as well as tuples from the right relation that didn’t match any from the left relation.
  • 45. Example sid Sname Rating Age 22 Swati 7 45 29 Ushma 1 33 31 Ruchita 8 55.5 32 Manthan 8 25.5 58 Amit 10 35 64 Arpit 3 63.5 Sid Bid Day 22 101 10/10/98 22 102 10/10/98 22 103 10/8/98 31 101 11/10/98 31 102 11/6/98 31 103 11/2/98 64 101 9/5/98 64 102 9/8/98 64 103 9/8/98 Bid bname Color 101 Marine Red 102 Clipper Green 103 Interlake Blue
  • 46. a) Find the names of sailors who have reserved boats 103. sname((σbid=103 Reserves) ⋈ Sailors) b) Find the names of sailors who have reserved a red boat. sname((σcolor=‘red’Boats) ⋈ Reserves ⋈ Sailors) c) Find the names of sailors who have reserved at least one boat. sname(Sailors ⋈ Reserves)
  • 47. d) Find the names of sailors who have reserved a red or green boat. (Tempboats, (σcolor=‘red’Boats) ∪ (σcolor=‘green’Boats)) sname(Tempboats ⋈ Reserves ⋈ Sailors) e) Find the names of sailors who have reserved all boats called Interlake. (Tempsids, (sid,bidReserves)/(bid(σbname=‘Interlake’Boats))) sname(Tempsids ⋈ Sailors)
  • 48. f) Find the sids of sailors with age over 20 who have not reserved a red boat. sid(σage>20Sailors) - sid((σcolor=‘red’Boats) ⋈ Reserves ⋈ Sailors) g) Find the colors of boats reserved by Lubber. color((σsname=‘Lubber’Sailors)Sailors ⋈ Reserves ⋈ Boats)