Database Chapter 6
Database Chapter 6
CHAPTER SIX
Introduction
2
Select Operation
The select operation selects a subset of tuples from a relation
instance that satisfies a given predicate (condition).
C (R)
A (R)
Regno
4
Cont’s
10
2. To display branch, section column of student table, use
the following command
Rename Operation
RS
Name RegNo
Bhanu 2
priya 4
15
… Binary Operations
16
Set Operations
Union Operation
Intersection Operation
For the set operations (Union, Intersection, Set difference) the two
relational operands R and S must have same type of tuples, this
condition is known as Union Compatibility.
Two relations R(A1, A2, … An) and S(B1, B2, … Bn) are said to
be union compatible if
For all set operations duplicates are eliminated from the result.
24 Relational calculus
Relational calculus is a non-procedural query language in
database management systems, guides users on what data is
needed without specifying how to obtain it.
In SQL we will get an error if the query is not correct but in the
case of QBE if the query is wrong either we get a wrong answer
or the query will not be going to execute but we will never get
any error.
{ t\| p(t) }
Where t is the tuple variable that runs over every Row, and
P(t) is the predicate logic expression or condition.
29 Example
Conts’….
30
Example 1: Write a TRC query to get all the data of customers
whose zip code is 12345.
TRC Query: {t \| t ∈ Customer ∧ t.Zipcode = 12345} or TRC
Query: {t \| Customer(t) ∧ t[Zipcode] = 12345 }
Workflow of query - The tuple variable "t" will go through every
tuple of the Customer table. Each row will check whether the
Cust_Zipcode is 12345 or not and only return those rows that
satisfies the Predicate expression condition.
Result of the TRC expression above:
1 Rohit 12345
4 Amit 12345
Conts’…….
31
Customer_ID
1
2
3
4
5
32 EXERCISES
Consider student table
FN LN AGE
A E 30
B F 31
C G 27
D H 28
where,
THANK YOU !