DB Chapter3
DB Chapter3
Basic concepts:
Note: If the WHERE clause is omitted all rows of data are deleted from the table.
DCL(data control language)
COUNT(attr)
SUM(attr)
MAX(attr)
MIN(attr)
AVG(attr)
Additional operations:
◦ Intersection, join, division, renaming
age
35.0
55.5
age(S2)
sid sname rating age
Selection 28 yuppy 9 35.0
58 rusty 10 35.0
Selects rows that satisfy
selection condition. rating 8(S2)
No duplicates in result!
Schema of result identical to
schema of (only) input
relation.
sname rating
Result relation can be the
input for another relational
yuppy 9
algebra operation! (Operator rusty 10
composition.)
sname,rating( rating 8(S2))
UNION INTERSECTION
Union, Intersection, Set-Difference
sid sname rating age
All of these operations take two 22 dustin 7 45.0
input relations, which must be 31 lubber 8 55.5
union-compatible: 58 rusty 10 35.0
◦ Same number of fields.
◦
44 guppy 5 35.0
`Corresponding’ fields have the same type.
28 yuppy 9 35.0
S1 S2
In domain relational calculus, filtering is done based on the domain of the
attributes and not based on the tuple values.
Syntax: { c1, c2, c3, ..., cn | F(c1, c2, c3, ... ,cn)}
where, c1, c2... etc represents domain of attributes(columns) and F defines the
formula including the condition for fetching the data.
For example,
{< name, age > | ∈ Student ∧ age > 17}
The above query will return the names and ages of the students in the table
Student who are older than 17.
Domain Relational Calculus (DRC)