What is Relational Algebra in DBMS in Hindi
Relational algebra, Relational databases में data के साथ कार्य करने का एक तरीका है। यह एक procedural query language है, जो database से data प्राप्त करने के लिए step by step निर्देश प्रदान करता है।यह tables के साथ कार्य करता है और नए tables का निर्माण करता है।
इसमें विभिन्न क्रियाएं जैसे विशिष्ट rows का चयन करना, कुछ columns को चुनना, tables को मिलना, विशिष्ट rows को ढूंढना आदि किए जाते हैं।
इन क्रियाओं का एक साथ उपयोग करके हम data को कई तरीके से बदल और प्राप्त कर सकते हैं। Relational algebra, SQL तथा अन्य database query languages का आधार है।
इसका उपयोग करके Relational databases, queries को तेजी से process करते हैं और सही result देते हैं।
Relational Algebra Operators in Hindi
Relational algebra में निम्न Operators का प्रयोग किया जाता है
Union(U)
Union (∪) operator दो समान tables(relations) को join(मिलाता) करता है और दोनों tables उपस्थित सभी rows को शामिल करता है।यह duplicate rows को हटाता है अर्थात एक हो row अगर दोनो tables में मौजूद है तो उसमें से केवल एक row को नए table में शामिल करता है। अतः जो नया table प्राप्त होता है उसमें सभी rows unique होते हैं।
Table A:
StudentID | Name |
---|---|
101 | Jay |
102 | Yash |
103 | Amit |
Table B:
StudentID | Name |
---|---|
101 | Jay |
104 | Rahul |
105 | Kamal |
Table A U Table B
StudentID | Name |
---|---|
101 | Jay |
102 | Yash |
103 | Amit |
104 | Rahul |
105 | Kamal |
Union (U) Table A और Table B के दोनो unique rows को नए Table में प्रदर्शित करता है तथा duplicate rows को हटाता है। जैसे ऊपर Table में 101, Jay row दोनों मे है
Difference(–)
Difference (–)operator ऐसे records को ढूंढता है जो पहले table में मौजूद है लेकिन दूसरे table में नहीं।यह पहले table में unique rows को ढूंढता है और यदि यही rows दूसरे table में भी है तो उन rows को दूसरे table से हटा देता है।
Table A:
EmployeeID | Name |
---|---|
101 | Ravi |
102 | Priyanshu |
103 | Sumit |
Table B:
EmployeeID | Name |
---|---|
102 | Priyanshu |
104 | Yash |
Table A – Table B:
EmployeeID | Name |
---|---|
101 | Ravi |
103 | Sumit |
ऊपर के example में difference operator (–) ऐसे rows को लौटता है जो Table A मैं उपस्थित है परंतु Table B में नहीं
Students Table:
Selection (σ)
Selection (σ) का उपयोग एक टेबल से दिए गए condition के आधार पर rows को filter करने के लिए किया जाता है। यह ऐसे rows को ही select करता है जो दिए गए condition को पूरा करते हैं।Students Table:
StudentID | Name | Result |
---|---|---|
201 | Ajay | Pass |
202 | Pawan | Fail |
203 | Sudhir | Pass |
204 | Kamal | Fail |
Selection: σ Result = 'Pass' (Students)
Output:
StudentID | Name | Result |
---|---|---|
201 | Ajay | Pass |
203 | Sudhir | Pass |
ऊपर के example में Students table से ऐसे rows को select किया गया है जिसका Result, Pass के बराबर है, अर्थात जो Pass है।
Projection (∏)
Projection (∏), एक table से विशिष्ट colum को select करता है और duplicate को हटाता है।पूरे table के बजाय केवल आवश्यक column को की प्राप्त करने में मदद करता है।
Table: Students
StudentID | Name | Course | Fees |
---|---|---|---|
001 | Tina | DCA | 10,000 |
002 | Neha | PGDCA | 13,000 |
003 | Amita | BCA | 40,000 |
Projection: ∏ StudentID, Course (Students)
Output:
StudentID | Course |
---|---|
001 | DCA |
002 | PGDCA |
003 | BCA |
Cartesian Product(X)
Cartesian Product (×) एक table के सभी rows को अन्य table के सभी rows के साथ मिलाता है।यह नई table का निर्माण करता है जिसमें दोनों tables के सभी संभावित rows pair उपस्थित रहती है।
यह table को बहुत बड़ा बना देता इसका उपयोग के selection या join operations के पहले करते हैं।
Table A:
ID |
---|
101 |
102 |
Table B:
Name |
---|
Tina |
Riya |
Cartesian Product (Table A ×Table B):
ID | Name |
---|---|
101 | Tina |
101 | Riya |
102 | Tina |
102 | Riya |
Intersection(∩)
Intersection (∩) का उपयोग दो tables के बीच में common records को ढूंढने के लिए होता है। यह केवल उन rows को लौटता है जो दोनों tables में उपस्थित है। intersection को कार्य करने के लिए दोनों tables में column की संख्या समान होनी चाहिए और उनके data types भी समान होनी चाहिए
Table A:
EmployeeID | Name |
---|---|
001 | Rakhi |
002 | Priya |
003 | Amita |
Table B:
EmployeeID | Name |
---|---|
002 | Priya |
004 | Tina |
003 | Amita |
Result: Table A ∩ Table B:
EmployeeID | Name |
---|---|
002 | Priya |
003 | Amita |
ऊपर example में Priya और Amita दोनो table में उपस्थित है।
DBMS के नोट्स को हिंदी में पढ़ने के लिए क्लिक करें
Rename(ρ)
Rename(ρ) operator का उपयोग tables या उसके column का नाम बदलने (Rename) के लिए किया जाता है।यह queries को पढ़ने के लिए आसान बनाने में मदद करता है और जब एक ही टेबल को एक से अधिक बार प्रयोग किया जाता है तो उसे होने वाले confusion को दूर करता है।
Example:
हम Rename operator का use करके Employee का नाम बदलकर Employee1 रखते है
ρ(Employee1, Employee)
Join
Join का प्रयोग एक सामान्य column का उपयोग करके दो tables को जोड़ने के लिए किया जाता है। यह संबंधित records को जोड़ने के द्वारा उपयोगी data को प्राप्त करने में मदद करता है।Join operator निम्न प्रकार के होते हैं।
Theta (θ) Join:
यह join दो tables की rows को जोड़ने के लिए एक condition का उपयोग करता है।इस condition में <, >, <=, >=, या != जैसे किसी भी comparison operator का उपयोग किया जा सकता है।
जब condition सही होती है, तब rows को जोड़ा जाता है। यह equi-join से अधिक लचीला है।
Left Outer Join:
यह Left table के सभी rows तथा right table से match होने वाले records को लौटाता है।
यदि right table से कोई match होने वाले records नही मिलते तो उसके बदले NULL values का use किया जाता है।
Right Outer Join:
यह Right table के सभी rows तथा Left table से match होने वाले records को लौटाता है।
यदि Left table से कोई match होने वाले records नही मिलते तो उसके बदले NULL values का use किया जाता है।
Full Outer Join:
यह join दोनों tables के सभी rows records को लौटाता है। जो records नहीं मिलते, उनमें NULL होता है।
Natural Join:
यह join दोनों tables में उन्हीं columns को जोड़ता है, जिनके नाम एक जैसे होते हैं।
यह duplicate columns को हटाता है और केवल match होने वाले rows को दिखाता है।
0 टिप्पणियाँ