Professional Documents
Culture Documents
Total No. of
Tuples = Set of
Cardinality permitted
of relation values for that
attribute =
Row =
Domain
Record =
Tuple
• Predefined row/column
format for storing
information.
• Relation = Table
Keys
▪ Super Key
• A super key is a set of one or more attributes whose values
uniquely identifies each record within a relation.
Candidate Key
(RollNo, Branch, Semester)
Candidate
Primary KeyKey Candidate Key
Alternate Key
EnrollNo (RollNo, Branch, Semester)
1 1 501 Akash CE
2 2 502 Mohit CI
3 4 504 Nitin CE
4 1 515 Harnish CI
Relational algebra operation
▪ It is a language for expressing relational database queries.
▪ It is a procedural query language.
▪ Operations are as below;
1. Selection
2. Projection
3. Division
4. Cartesian product / Cross product
5. Rename
6. Set Operations
• Union
• Intersection
• Difference / Minus
Selection operation
▪ Retrieve one or more than one row/s (tuples) that satisfies the
condition/s with all columns (attribute)
▪ Symbol : σ (Sigma)
▪ Notation : σ(condition) <Table name>
▪ Operators:
• =,!=, <,>,<=,>=, Λ(AND), ∨(OR)
▪ Example: Student
▪ Output:
▪ Output:
Name Departmen
t
Ram Computer
Param IT
Krishti Computer
Balram Electrical
Combined Projection & Selection Operation
▪ Example: Display rollno, name & department of “CE” department
students. RollNo Name Department SPI
101 Raj CE 8
Student 102 Meet ME 9
103 Harsh EE 8
104 Punit CE 9
∏ RollNo, Name, Department (σ Department=‘CE’ (Student) )
1
2
RollNo Name Department SPI
101 Raj CE 8
Output-1
104 Punit CE 9
B
1 B
2 B
3
A A/ A/ A/
B1 B2 B3
Cartesian product / Cross product
▪ Combines information of two tables
▪ It will multiply each row(tuples) of first table(relation) to each
row(tuples) of second table(relation).
▪ Symbol : X (Cross)
▪ Notation : Relation1 X Relation2
▪ Resultant Relation:
1. Relation1 have n1 attribute and Relation2 have n2 attribute then
resultant relation will have n1+n2 attribute.
2. Relation1 have n1 tuples and Relation2 have n2 tuples then
resultant relation will have n1*n2 tuples.
3. If both relations have some attribute with same name, then it
will be distinguished by relation1.attribute and
relation2.attribute
Cartesian product example
Student Faculty
Stu_I Stu_RollN Name Department Fac_I Fac_Nam Department
D o D e
1 101 Ram Computer 1 Nitin Computer
2 105 Param IT 2 Chintan IT
Student X Faculty
Stu_I Stu_RollN Name Departmen Fac_I Fac_Nam Faculty.Deparmtn
D o t D e et
1 101 Ram Computer 1 Nitin Computer
1 101 Ram Computer 2 Chintan IT
2 105 Param IT 1 Nitin Computer
2 105 Param IT 2 Chintan IT
Set Operators
▪ Operation: All of these operations take two input relations, which
must be union - compatible:
1. Both relations have same (equal) number of columns
Student U Faculty
Raj
Student Faculty Suresh
Raj Nitin Meet
Suresh Raj Nitin
Meet Akash Akash
Intersect operator
▪ Symbol: ∩ (Intersection)
▪ Notation: Relation1 ∩ Relation2
▪ Operation: Returns the records which are common from both
relations.
A.CPI
8
7
Rename Operator
▪ Example: Student
SELECT * FROM
staff
WHERE dep_id IN
(SELECT dep_id FROM department where dep_id='2');