Table of Contents
▶
- Keys in DBMS in Hindi – DBMS में Keys क्या हैं?
- Types of Keys in DBMS
- Advantages of Keys in DBMS in Hindi – Keys के फायदे
- Disadvantages of Keys in DBMS in Hindi – Keys के नुकसान
- Difference Between Primary Key and Foreign Key in Hindi – Primary Key और Foreign Key में अंतर
- Difference Between Primary Key and Unique Key in Hindi – Primary Key और Unique Key में अंतर
- FAQs
Keys in DBMS in Hindi – DBMS में Keys क्या हैं?
Endless Horse – Think You Can Find the End? Play The Game- Key, DBMS (Database Management System) में एक Attribute या Attributes का Set होता है, जो Table की हर Row को Unique तरीके से पहचानता है।
- इसकी मदद से Table में दो एक जैसी Rows नहीं बन पातीं और हर Record को अलग से खोजा जा सकता है।
- Key का इस्तेमाल अलग-अलग Tables को आपस में जोड़ने के लिए भी किया जाता है।
- इसमें एक Column भी हो सकता है और एक से ज़्यादा Columns भी, यह इस पर निर्भर करता है कि Row को पहचानने के लिए कितनी जानकारी चाहिए।
- Relational Database में हर Table के लिए Keys पहले से सोचकर चुनी जाती हैं।
- Keys को Database Designer तय करता है, और DBA इन्हें Database में लागू करके maintain करता है।
- SQL में Keys को Constraints के रूप में define किया जाता है, जैसे PRIMARY KEY और FOREIGN KEY।
- अगर Key सही नहीं चुनी जाए, तो Table में Duplicate Rows आ सकती हैं या Tables का आपसी Link टूट सकता है।
Example of Keys (उदाहरण)
मान लीजिए Student Table में Roll_No, Name, Email, Phone और Dept_ID Columns हैं। इसमें हर Student का Roll_No अलग होता है, इसलिए Roll_No से कोई भी Row सीधे पहचानी जा सकती है। आगे की सभी Keys इसी Table के उदाहरण से समझाई गई हैं।
Types of Keys in DBMS in hindi
DBMS में मुख्य रूप से 7 तरह की Keys इस्तेमाल होती हैं।
1. Super Key in DBMS
Super Key ऐसे एक या एक से अधिक Attributes का Set होता है, जो किसी Table की प्रत्येक Row को Unique तरीके से Identify कर सकता है। इसमें आवश्यक Attributes के साथ Extra Attributes भी शामिल हो सकते हैं।
Features of Super Key
- Unique Identification: Table की प्रत्येक Row को अलग-अलग पहचानती है।
- Single या Multiple Attributes: एक या अधिक Attributes से बन सकती है।
- Extra Attributes: इसमें अनावश्यक Attributes भी हो सकते हैं।
- Multiple Super Keys: एक Table में कई Super Keys हो सकती हैं।
- Candidate Key से संबंध: प्रत्येक Candidate Key एक Super Key होती है, लेकिन प्रत्येक Super Key Candidate Key नहीं होती।
Example: Student Table में यदि Roll_No और Email Unique हैं, तो {Roll_No}, {Email} और {Roll_No, Name} Super Keys हो सकती हैं।
2. Candidate Key in DBMS
Candidate Key एक Minimal Super Key होती है, जो Table की प्रत्येक Row को Unique तरीके से Identify करती है। Minimal का अर्थ है कि इसमें कोई Extra Attribute नहीं होता। यदि इसमें से कोई Attribute हटा दिया जाए, तो बचा हुआ Set सभी Rows को Unique तरीके से पहचानने में सक्षम नहीं रहता।
Features of Candidate Key
- Unique Identification: प्रत्येक Row को Unique तरीके से पहचानती है।
- Minimal Attributes: इसमें कोई अनावश्यक Attribute नहीं होता।
- Multiple Candidate Keys: एक Table में कई Candidate Keys हो सकती हैं।
- Primary Key का आधार: इनमें से किसी एक को Primary Key चुना जाता है।
- Uniqueness और Minimality: Candidate Key में दोनों गुण आवश्यक हैं।
Example: Student Table में यदि Roll_No और Email दोनों Unique हैं, तो {Roll_No} और {Email} Candidate Keys हो सकती हैं।
3. Primary Key in DBMS
Primary Key वह Candidate Key होती है, जिसे Table की प्रत्येक Row को Unique तरीके से Identify करने के लिए चुना जाता है। एक Table में केवल एक Primary Key Constraint होता है, लेकिन वह एक या एक से अधिक Columns से बन सकता है। Primary Key में Duplicate और NULL Values की अनुमति नहीं होती।
Features of Primary Key
- Unique Values: इसकी Values Duplicate नहीं हो सकतीं।
- No NULL Values: इसमें NULL Value की अनुमति नहीं होती।
- One Primary Key: एक Table में केवल एक Primary Key Constraint होता है।
- Single या Composite: यह एक या कई Columns से बन सकती है।
- Record Identification: इसका उपयोग किसी विशेष Record को पहचानने में होता है।
- Relationship: दूसरी Table की Foreign Key इसे Reference कर सकती है।
Example: Student Table में Roll_No को Primary Key बनाया जा सकता है, क्योंकि प्रत्येक Student का Roll_No अलग होता है।
4. Alternate Key in DBMS
Alternate Key वह Candidate Key होती है, जिसे Table की Primary Key के रूप में नहीं चुना गया हो। जब किसी Table में एक से अधिक Candidate Keys होती हैं, तब एक को Primary Key चुना जाता है और बाकी Candidate Keys Alternate Keys कहलाती हैं।
Features of Alternate Key
- Candidate Key का हिस्सा: यह Candidate Keys में से एक होती है।
- Unique Identification: यह प्रत्येक Row को Unique तरीके से पहचान सकती है।
- Primary Key नहीं होती: इसे Primary Key के रूप में नहीं चुना जाता।
- Minimality: इसमें कोई अनावश्यक Attribute नहीं होता।
- Multiple Alternate Keys: एक Table में कई Alternate Keys हो सकती हैं।
Example: यदि Student Table में Roll_No और Email Candidate Keys हैं और Roll_No को Primary Key चुना गया है, तो Email Alternate Key होगी।
5. Unique Key in DBMS
Unique Key एक Database Constraint है, जो किसी Column या Columns के Combination में Duplicate Values को रोकता है। इसका उपयोग उन Attributes की Values को अलग रखने के लिए किया जाता है जिन्हें दो या अधिक Records में समान नहीं होना चाहिए। NULL Values का व्यवहार DBMS के अनुसार अलग हो सकता है।
Features of Unique Key
- Duplicate Values पर रोक: निर्धारित Column या Columns में Duplicate Values को रोकता है।
- Multiple Constraints: एक Table में कई UNIQUE Constraints हो सकते हैं।
- NULL Values: NULL की अनुमति और उसकी संख्या DBMS पर निर्भर करती है।
- Single या Multiple Columns: Constraint एक या अधिक Columns पर लगाया जा सकता है।
- Data Integrity: निर्धारित Columns में Duplicate Values को रोककर Data Integrity बनाए रखने में मदद करता है।
Example: Student Table में Email Column पर UNIQUE Constraint लगाया जा सकता है, ताकि दो Students का Email Address समान न हो।
6. Foreign Key in DBMS
Foreign Key किसी Table का एक Column या Columns का Set होता है, जो दूसरी Table की Primary Key या उपयुक्त UNIQUE Key को Reference करता है। इसका मुख्य उद्देश्य Tables के बीच Relationship स्थापित करना और Referential Integrity बनाए रखना है। यदि Constraint NULL की अनुमति देता है, तो Foreign Key में NULL भी हो सकता है।
Features of Foreign Key
- Relationship Between Tables: दो Tables के बीच संबंध स्थापित करती है।
- Referential Integrity: ऐसे References को रोकती है जिनका संबंधित Parent Record मौजूद नहीं है।
- Referenced Key: दूसरी Table की Primary Key या उपयुक्त UNIQUE Key को Reference करती है।
- NULL Values: Constraint की अनुमति होने पर NULL हो सकता है।
- Duplicate Values: Foreign Key में Duplicate Values हो सकती हैं।
- Composite Foreign Key: यह एक से अधिक Columns से भी बन सकती है।
Example: Department Table में Dept_ID Primary Key है और Student Table का Dept_ID उसे Reference करता है, इसलिए Student Table का Dept_ID Foreign Key है।
7. Composite Key in DBMS
Composite Key दो या दो से अधिक Attributes के Combination से बनती है। जब कोई एक Attribute अकेले सभी Records को Unique तरीके से Identify नहीं कर पाता, लेकिन उनका Combination ऐसा कर सकता है, तब Composite Key का उपयोग किया जाता है।
Features of Composite Key
- Multiple Attributes: इसमें कम से कम दो Attributes होते हैं।
- Combined Uniqueness: पूरा Combination Record को Unique तरीके से पहचानता है।
- Individual Values Repeat हो सकती हैं: प्रत्येक Attribute की Value अलग-अलग Rows में दोहराई जा सकती है, लेकिन पूरा Combination Unique होना चाहिए।
- Primary Key के रूप में उपयोग: इसे Table की Primary Key बनाया जा सकता है।
- Minimal Combination: Candidate Key के रूप में उपयोग होने पर कोई Attribute हटाने से Uniqueness समाप्त होनी चाहिए।
Example: Enrollment Table में {Roll_No, Course_ID} Composite Key हो सकती है, क्योंकि एक Student कई Courses में और एक Course में कई Students Enrollment कर सकते हैं, लेकिन दोनों का Combination प्रत्येक Enrollment को Unique तरीके से पहचानता है।
Advantages of Keys in DBMS in Hindi – Keys के फायदे
- Unique Identification: Keys की मदद से Table की हर Row को अलग से पहचाना जा सकता है।
- Duplicate Control: Primary Key और Unique Key एक जैसी Values को Table में दोबारा आने से रोकती हैं।
- Table Relationship: Foreign Key से अलग-अलग Tables आपस में जुड़ जाती हैं, इसलिए Data को कई Tables में बाँटकर रखा जा सकता है।
- Fast Searching: Primary Key पर आमतौर पर Index बनता है, इसलिए Row को खोजना तेज़ होता है।
- Data Integrity: Foreign Key यह पक्का करती है कि किसी Table में ऐसी Value न आए, जो दूसरी Table में मौजूद ही नहीं है।
Disadvantages of Keys in DBMS in Hindi – Keys के नुकसान
- Key Selection: जब Table में कई Candidate Keys हों, तब सही Key चुनना मुश्किल हो सकता है।
- Extra Storage: Keys पर बनने वाले Index के लिए Extra Storage की ज़रूरत पड़ती है।
- Slower Insert and Update: नई Row डालते समय DBMS को Key की Value check करनी पड़ती है, इसलिए Insert और Update थोड़े धीमे हो सकते हैं।
- Delete Restriction: Foreign Key होने पर Parent Table की Row आमतौर पर तब तक delete नहीं हो सकती, जब तक उससे जुड़ी Child Rows मौजूद हों।
- Composite Key Complexity: Composite Key में कई Columns होने से Queries लिखना और Tables को जोड़ना Complex हो जाता है।
Difference Between Primary Key and Foreign Key in Hindi – Primary Key और Foreign Key में अंतर
| Basis | Primary Key | Foreign Key |
|---|---|---|
| Purpose | Primary Key Table की हर Row को Unique तरीके से पहचानती है। | Foreign Key एक Table को दूसरी Table से जोड़ती है। |
| NULL Value | Primary Key में NULL Value नहीं हो सकती। | Foreign Key में NULL Value हो सकती है। |
| Duplicate Values | Primary Key की Values Table में repeat नहीं हो सकतीं। | Foreign Key की Values Table में repeat हो सकती हैं। |
| Number in a Table | एक Table में सिर्फ एक Primary Key होती है। | एक Table में एक से ज़्यादा Foreign Keys हो सकती हैं। |
| Reference | Primary Key अपनी ही Table की Rows को पहचानती है और किसी दूसरी Table पर निर्भर नहीं होती। | Foreign Key दूसरी Table की Primary Key को refer करती है। |
Difference Between Primary Key and Unique Key in Hindi – Primary Key और Unique Key में अंतर
| Basis | Primary Key | Unique Key |
|---|---|---|
| Number in a Table | एक Table में सिर्फ एक Primary Key हो सकती है। | एक Table में एक से ज़्यादा Unique Keys हो सकती हैं। |
| NULL Value | Primary Key में NULL Value allow नहीं होती। | Unique Key में NULL Value allow की जा सकती है। |
| Main Use | Primary Key का मुख्य काम Table की Rows को पहचानना है। | Unique Key का मुख्य काम Column में एक जैसी Values को आने से रोकना है। |
