Q.3)

 Describe any five operations of relational algebra along with suitable examples.


Relational Algebra mein Operators

Relational algebra mein kai basic operators hote hain jo humein database ki relational tables se data fetch aur manipulate karne mein madad karte hain, taaki relational data par kuch specific operations perform kiye ja sakein. Basic operators fundamental operations hote hain jisme selection (σ), projection (π), union (U), set difference (-), Cartesian product (×), aur rename (ρ) shamil hain.


[Diagram: Relational Algebra mein Operators ke Types]

  • Basic Operators → Cartesian Product (×), Select (σ), Union (U), Set Difference (-), Rename (ρ), Project (π)

  • Derived Operators → Division (÷), Intersection (∩), Join

    • Join → Inner, Outer

      • Inner → Equi, Conditional (θ), Natural (⋈)




1. Selection (σ)

  1. Selection sirf un rows (tuples) ko relation se retrieve karta hai jo di gayi condition ko satisfy karti hain.

  2. Yeh ek predicate ke base par horizontal filtering perform karta hai.

  3. Yeh attributes (columns) ki ginti ko change nahi karta, sirf rows ko karta hai.

  4. Iska use tab hota hai jab humein table se specific records chahiye hote hain.

  • Syntax: σ(condition)(Relation)

  • Example: σ(Age > 18)(Student)

2. Projection (π)

  1. Projection ek relation se sirf selected columns (attributes) ko retrieve karta hai.

  2. Yeh attribute names ke base par vertical filtering perform karta hai.

  3. Result mein duplicate rows automatically remove ho jati hain.

  4. Iska use tab hota hai jab sirf specific fields ki zaroorat hoti hai.

  • Syntax: π(Attribute1, Attribute2)(Relation)

  • Example: π(Name, Salary)(Employee)

3. Union ( U )

  1. Union do relations ke tuples ko ek mein combine karta hai.

  2. Duplicate tuples remove kar diye jaate hain.

  3. Dono relations union-compatible hone chahiye (yani dono mein same attributes hone chahiye).

  4. Yeh do datasets ke results ko merge karne ke liye use hota hai.

  • Syntax: Relation1 U Relation2

  • Example: Student1 U Student2

4. Set Difference ( - )

  1. Set difference wo tuples return karta hai jo first relation mein hain lekin second mein nahi hain.

  2. Dono relations union-compatible hone chahiye.

  3. Yeh exclusive values find karne ke liye use hota hai.

  4. Yeh sets ki mathematical subtraction ke equivalent hota hai.

  • Syntax: Relation1 – Relation2

  • Example: Student1 – Student2

5. Cartesian Product ( × )

  1. Yeh ek relation ke har tuple ko dusre relation ke har tuple ke saath combine karta hai.

  2. Saare possible pairs (m×n tuples) produce karta hai.

  3. Yeh JOIN operations ka basis (aadhar) hai.

  4. Output mein dono relations ke saare attributes hote hain.

  • Syntax: Relation1 × Relation2

  • Example: Employee × Department

6. Rename ( ρ )

  1. Rename kisi relation ya uske attributes ko ek naya naam deta hai.

  2. Queries mein ambiguity (confusion) avoid karne ke liye use hota hai.

  3. Yeh self-joins mein bahut madad karta hai.

  4. Yeh data ko modify nahi karta, sirf labels change karta hai.

  • Syntax (rename relation): ρ(NewName)(Relation)

  • Syntax (rename attribute): ρ(NewAttr / OldAttr)(Relation)

  • Example: ρ(Emp)(Employee)

7. Join (⋈)

  1. Join ek condition ke base par do relations se related tuples ko combine karta hai.

  2. Yeh irrelevant combinations ko eliminate karke meaningful results produce karta hai.

  3. Iske types mein Natural Join, Equi Join, aur Theta Join shamil hain.

  4. Yeh Cartesian product se zyada powerful hota hai.

  • Syntax (Theta Join): Relation1 ⋈ Condition Relation2

  • Example: Employee ⋈ Employee.DeptID = Department.DeptID Department

8. Left Outer Join (⟕)

  1. Yeh left relation ke saare tuples return karta hai.

  2. Right relation se matching tuples include hote hain; non-matching tuples NULL ban jaate hain.

  3. Yeh left-side ki information ko preserve karta hai.

  4. Incomplete matches ke cases mein yeh bahut useful hota hai.

  • Syntax: Relation1 ⟕ Relation2

  • Example: Employee ⟕ Department

9. Right Outer Join (⟖)

  1. Yeh right relation ke saare tuples return karta hai.

  2. Non-matching left tuples NULL ke roop mein appear hote hain.

  3. Yeh right-side ki information ko preserve karta hai.

  4. Jab right table primary focus ho tab yeh useful hota hai.

  • Syntax: Relation1 ⟖ Relation2

  • Example: Employee ⟖ Department

10. Full Outer Join (⟗)

  1. Yeh dono relations ke saare tuples return karta hai.

  2. Unmatched values NULL se fill ho jati hain.

  3. Yeh left aur right outer joins ko combine karta hai.

  4. Yeh ensure karta hai ki dono sides se koi data lost na ho.

  • Syntax: Relation1 ⟗ Relation2

  • Example: Employee ⟗ Department

11. Intersection ( ∩ )

  1. Intersection wo tuples return karta hai jo dono relations mein common hote hain.

  2. Dono relations union-compatible hone chahiye.

  3. Yeh sets ke intersection jaisa hi hota hai.

  4. Yeh common values find karne ke liye use hota hai.

  • Syntax: Relation1 ∩ Relation2

  • Example: Student1 ∩ Student2

12. Division ( ÷ )

  1. Division ka use "for all" (sab ke liye) queries ke liye hota hai.

  2. Yeh ek relation mein un tuples ko find karta hai jo dusre relation ke har tuple se related hon.

  3. Iska structure Dividend ÷ Divisor hota hai.

  4. Yeh un queries mein use hota hai jaise "un students ko find karo jinhone saare courses ke liye register kiya hai".

  • Syntax: Relation1 ÷ Relation2

  • Example: Find students who have enrolled in ALL courses → STUDENT ÷ COURSE.

Comments

Popular posts from this blog

Q.1)

Q.2)