Key, dbms में एक या एक से अधिक कॉलम columns का सेट है जो की table में हर एक पंक्ति (row) को विशिष्ट (unique) रूप से पहचानता है। प्राइमरी key ensure करती है कि किसी भी दो पंक्ति (rows) में सामान values न हो।
Types of Keys
Keys dbms में निम्नलिखित प्रकार की होती है –
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 | |
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 | 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 | |
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 | 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
(BothEmail
andPhoneNumber
columns unique vlaues होनी चाहिए पूरी टेबल में)
References
Javatpoint – https://www.javatpoint.com/dbms-keys?=
Wikipedia – https://en.wikipedia.org/