Relational Algebra
Relational Algebra ek procedural query language hai. Iska matlab hai ki isme hum database ko batate hain ki "kya" data chahiye aur "kaise" nikalna hai. Yeh set theory ke operations par based hai aur SQL ka theoretical foundation maana jaata hai.
Core Operations
- Selection (σ): Rows ko filter karta hai, bilkul SQL ke
WHEREclause ki tarah. Example:σ (marks > 80) (Student) - Projection (π): Columns ko select karta hai, bilkul SQL ke
SELECT ColumnNameki tarah. Yeh by default duplicate rows hata deta hai. Example:π (Name, Age) (Student) - Union (∪): Do tables (jo union-compatible hon) ki saari rows ko combine karta hai.
- Set Difference (-): Wo rows nikalta hai jo pehle table me hain par doosre me nahi.
- Cartesian Product (×): Do tables ke har row ko doosre table ke har row ke saath jod deta hai.
- Rename (ρ): Isse hum relations (tables) ya unke attributes ka naam badal sakte hain.
Derived Operations (Joins)
Joins core operations se derive hote hain. Inka kaam do tables ko ek specific condition par jodna hai.
- Natural Join (⋈): Yeh automatically dono tables ke common columns par join karta hai.
- Theta Join: Yeh kisi bhi condition (theta) jaise
(>, <, =)par join karta hai. - Outer Joins (Left, Right, Full): Yeh un rows ko bhi result me rakhte hain jinka match doosre table me nahi milta, aur unki jagah
NULLdaal dete hain.