Website/App design एवं college projects आदि के लिए संपर्क करें – 8085589371

Key, dbms में एक या एक से अधिक कॉलम columns का सेट है जो की table में हर एक पंक्ति (row) को विशिष्ट (unique) रूप से पहचानता है। प्राइमरी key ensure करती है कि किसी भी दो पंक्ति (rows) में सामान values न हो।

  • Keys का उपयोग DBMS में डाटा सर्च करने के लिए करते है।
  • Keys Relational DBMS एक Basic लेकिन बहुत महत्वपूर्ण Concept, जिसका उपयोग पड़ते समय आय चाहे न आये लेकिन जब डेटाबेस डिज़ाइन करते है तब जरूर आता है।

Types of Keys

Primary Key

Primary Key किसी टेबल में एक या एक से अधिक कॉलम columns का सेट है जो की table में हर एक पंक्ति (row) को विशिष्ट (unique) रूप से पहचानता (identifies) है। 

  • Uniqueness: प्राथमिक key कॉलम में प्रत्येक मान अद्वितीय होना चाहिए।
  • Non-null: Primary key columns के पास NULL values नहीं होनी चाहिए।
  • Single table constraint: हर एक टेबल के पास केवल और केवल एक प्राइमरी key होनी चाहिए।

यहाँ पर प्राइमरी key studentid है एवं ईमेल एक candidate  key है। 

StudentID Name Age Major Email
1 Alice Smith 20 Computer Science
alice@example.com
2 Bob Johnson 22 Mathematics
bob@example.com
3 Carol Davis 21 Physics
carol@example.com

Super Key

Super key एक या अधिक columns का एक सेट है, जो सामूहिक रूप से, किसी तालिका में एक पंक्ति को विशिष्ट रूप से पहचान सकती है। सभी candidate keys, super key हैं, लेकिन सभी super keys candidate keys नहीं हैं।

Table – Students

StudentID Name Age Major Email PhoneNumber
1 Alice Smith 20 Computer Science alice@example.com 1234567890
2 Bob Johnson 22 Mathematics bob@example.com 2345678901
3 Carol Davis 21 Physics carol@example.com 3456789012

Example: Students table में, {StudentID}, {StudentID, Email}, और {StudentID, PhoneNumber}सभी super keys हैं।

Foreign Key

Foreign key, एक या एक से अधिक columns का  combination है, जो दो टेबल के बीच में रिलेशनशिप एस्टब्लिश स्थापित करती है।   

    • Can be null – Foreign key कॉलम में NULL value हो सकते हैं। 

Table – Enrollments

EnrollmentID StudentID CourseID
101 1 501
102 2 502
103 3 503
104 1 504

Foreign Key: यहाँ पर StudentID foreign key है। 

Candidate Key

एक candidate के एक कॉलम या कॉलम कॉम्बिनेशन है जो की uniquely हर row को, टेबल में। एक टेबल के पास multiple  candidate keys हो सकती है, इनमे से एक हो प्राइमरी key चुना जाता है।

StudentID Name Age Major Email
1 Alice Smith 20 Computer Science
alice@example.com
2 Bob Johnson 22 Mathematics
bob@example.com
3 Carol Davis 21 Physics
carol@example.com

Composite Key

एक Composite key एक कॉलम या कॉलम कॉम्बिनेशन है जो की row uniquely identify करता  टेबल में। यह की use होती है – जब single sufficient नहीं होता है हर एक row को identify करने के लिए।

StudentID CourseID Grade
1 501 A
2 502 B
3 503 A
1 504 B

Composite Key: {StudentID, CourseID} (The combination of StudentID and CourseID uniquely identifies each enrollment record).

Unique Key

एक unique key, एक कॉलम या कॉलम कॉम्बिनेशन है जो की यह सुनिश्चित करता है की टेबल में सभी rows यूनिक हो। 

EmployeeID Name Email PhoneNumber
1 John Miller john@example.com 1234567890
2 Sarah Brown sarah@example.com 2345678901
3 Emily Clark emily@example.com 3456789012
  • Primary Key: EmployeeID
  • Unique Keys: Email, PhoneNumber (Both Email and PhoneNumber columns unique vlaues होनी चाहिए पूरी टेबल में)

References

PDF Notes Link

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top