Data Integrity
Data Integrity
Lecture 5
Unary Operations
Binary Operations
Unary Operations
The operations which involve only one relation are called
unary operation. The following operations are the unary
operations
Selection
Projection
Binary Operations
The operations which involve pairs of relations are called
binary operations. A binary operation uses two relations as
input and produces a new relation as output. Binary
operations are
Union
Set Difference
Cartesian Product
Unary Operation
Selection Operation
The selection operation is a unary operation. The selection operator
is sigma σ. It acts like a filter on a relation. It returns only a certain
number of tuples. It selects the tuples using a condition.
σ CONDITION (R)
Comparison Operation
= < > ≤ ≥ =/=
Logical Operation
(and) (or) (Not)
For Example
Select a student where name is ALI from Student table.
σ Name=’ALI’ (Student)
Select a student where name is ALI and AGE is 24 from Student table.
σ Name=’ALI’ Age=24 (Student)
Select a student where name is ALI or AGE is 24 from Student table.
σ Name=’ALI’ Age=24 (Student)
Select a student where name is ALI and AGE is not 24 from Student
table.
σ Name=’ALI’ Age =/= 24 (Student)
Select a student where name is not ALI and AGE is not 24 from Student
table.
σ (Name=’ALI’ Age = 24) (Student)
Projection
Projection is also a unary operation. The projection operation is pi
π. It limits the attributes returned from the original relation.
π ATTRIBUTE (Student)
Select name and AGE from Student table.
π Name,Age (Student)
Select name Where AGE is 24 from Student table.
π Name(σ Age =24 (Student))
Select Name and Rollno of student where name is Ali or AGE is 24
from Student table.
π Name,Rollno (σ Name=’Ali Age=24 (Student))
Binary Operation
Union
The Union operation of two relations combines the tuples of
both relations to produce a third relation. If two relations
contain identical tuples, the duplicate tuples are eliminated.
Union operation is commutative. The resulting relation has
the same degree as the original relation.
A U B = B UA
A ∩ B = B ∩A
Example
Result(B ∩A)
Difference
The difference operation works on two relations. It produces
a relation that contains tuples that occur in the first relation
but not in second. Difference operation is not commutative.
A - B =/= B - A
Example