Exam-ready answer with definition, explanation, example, comparison, and conclusion.
সমস্ত ক্যান্ডিডেট কী সুপারকী হলেও সমস্ত সুপারকী কি ক্যান্ডিডেট কী নয় কেন? উদাহরণসহ ব্যাখ্যা কর।
DBMS বা Relational Database Management System-এ Key হলো এমন attribute বা attribute-এর set, যার সাহায্যে relation বা table-এর প্রতিটি tuple বা row-কে uniquely identify করা যায়।
Database table-এ duplicate record এড়ানো, data integrity বজায় রাখা এবং table-এর records সহজে identify করার জন্য key অত্যন্ত গুরুত্বপূর্ণ।
সহজ ভাষায়: Key হলো table-এর এমন column বা column group, যার মাধ্যমে প্রত্যেকটি row আলাদাভাবে চেনা যায়।
Super Key হলো এমন একটি attribute বা attribute set, যা relation-এর প্রতিটি tuple-কে uniquely identify করতে পারে।
Super Key-এর মধ্যে extra বা unnecessary attribute থাকতে পারে। অর্থাৎ tuple uniquely identify করার জন্য যত attribute দরকার, তার চেয়ে বেশি attribute থাকলেও সেটি Super Key হতে পারে।
Definition: A super key is an attribute or a set of attributes that can uniquely identify each tuple in a relation.
Candidate Key হলো এমন একটি minimal Super Key, যার সাহায্যে relation-এর প্রতিটি tuple uniquely identify করা যায় এবং যার মধ্যে কোনো unnecessary attribute থাকে না।
Candidate Key থেকে কোনো attribute বাদ দিলে সেটি আর tuple uniquely identify করতে পারবে না। তাই Candidate Key সবসময় minimal হয়।
Definition: A candidate key is a minimal super key that uniquely identifies each tuple in a relation and contains no redundant attribute.
সমস্ত Candidate Key হলো Super Key, কিন্তু সমস্ত Super Key Candidate Key নয়।
কারণ Candidate Key হলো Super Key-এর minimal form। Candidate Key tuple uniquely identify করে এবং এতে কোনো extra attribute থাকে না। কিন্তু Super Key tuple uniquely identify করলেও এতে অতিরিক্ত attribute থাকতে পারে।
Exam Point: Candidate Key must be minimal, but Super Key may not be minimal. এই কারণেই সব Candidate Key Super Key হলেও সব Super Key Candidate Key নয়।
ধরা যাক, একটি Student table আছে:
| Roll_No | Student_Name | Phone | Department | |
|---|---|---|---|---|
| 101 | Rahul | rahul@example.com | 9876543210 | Computer Science |
| 102 | Riya | riya@example.com | 9876543211 | Commerce |
| 103 | Karim | karim@example.com | 9876543212 | Arts |
এখানে প্রত্যেক student-এর Roll_No, Email এবং Phone আলাদা বা unique ধরা হয়েছে।
উপরের Student table-এ নিচের attribute বা attribute set-গুলি Super Key হতে পারে:
{Roll_No}
{Email}
{Phone}
{Roll_No, Student_Name}
{Roll_No, Department}
{Email, Phone}
{Roll_No, Email, Phone}
কারণ এগুলির প্রতিটি set-এর সাহায্যে student record uniquely identify করা যায়। তবে সব set minimal নয়।
যেমন {Roll_No, Student_Name} একটি Super Key, কারণ Roll_No নিজেই student uniquely identify করতে পারে। এখানে Student_Name extra attribute হিসেবে যুক্ত হয়েছে।
Candidate Key হতে হলে key-টি minimal হতে হবে। অর্থাৎ key থেকে কোনো attribute বাদ দিলে uniqueness নষ্ট হয়ে যাবে।
উপরের Student table-এ Candidate Key হতে পারে:
{Roll_No}
{Email}
{Phone}
কারণ Roll_No, Email এবং Phone প্রত্যেকটি আলাদাভাবে student record uniquely identify করতে পারে এবং এগুলির মধ্যে কোনো extra attribute নেই।
সমস্ত Super Key Candidate Key নয়, কারণ Super Key-এর মধ্যে unnecessary বা redundant attribute থাকতে পারে। Candidate Key হতে হলে Super Key-টি minimal হতে হবে।
{Roll_No} → Candidate Key এবং Super Key
{Roll_No, Student_Name} → Super Key কিন্তু Candidate Key নয়
এখানে {Roll_No} student uniquely identify করতে পারে। তাই এটি Candidate Key। কিন্তু {Roll_No, Student_Name} student uniquely identify করলেও Student_Name দরকার নেই। Roll_No একাই যথেষ্ট।
তাই {Roll_No, Student_Name} minimal নয়। এজন্য এটি Super Key হলেও Candidate Key নয়।
+----------------------------------+
| Super Keys |
| |
| {Roll_No, Name} |
| {Email, Phone} |
| {Roll_No, Department} |
| |
| +---------------------+ |
| | Candidate Keys | |
| | | |
| | {Roll_No} | |
| | {Email} | |
| | {Phone} | |
| +---------------------+ |
| |
+----------------------------------+
এই diagram থেকে বোঝা যায় Candidate Key হলো Super Key-এর একটি অংশ বা subset। কিন্তু Super Key-এর সব element Candidate Key নয়।
| বিষয় | Super Key | Candidate Key |
|---|---|---|
| Definition | Tuple uniquely identify করতে পারে | Minimal Super Key যা tuple uniquely identify করে |
| Minimality | Minimal হওয়া বাধ্যতামূলক নয় | Minimal হওয়া বাধ্যতামূলক |
| Extra Attribute | Extra attribute থাকতে পারে | Extra attribute থাকে না |
| Number | Super Key-এর সংখ্যা সাধারণত বেশি হয় | Candidate Key-এর সংখ্যা তুলনামূলক কম হয় |
| Relation | সব Super Key Candidate Key নয় | সব Candidate Key Super Key |
| Example | {Roll_No, Name} | {Roll_No} |
একটি table-এ একাধিক Candidate Key থাকতে পারে। এই Candidate Key-গুলির মধ্যে একটি key-কে Primary Key হিসেবে নির্বাচন করা হয়।
উদাহরণস্বরূপ, Student table-এ Candidate Key হতে পারে:
{Roll_No}
{Email}
{Phone}
এর মধ্যে database designer Roll_No-কে Primary Key হিসেবে নির্বাচন করতে পারে। তখন Email এবং Phone alternate key হিসেবে থাকতে পারে।
একটি college database-এ Student-এর Roll_No unique। তাই Roll_No দিয়ে student record সহজে identify করা যায়। আবার Roll_No-এর সঙ্গে Student_Name যোগ করলেও record identify করা যাবে।
Roll_No = Candidate Key
Roll_No + Student_Name = Super Key but not Candidate Key
কারণ Student_Name বাদ দিলেও Roll_No দিয়ে student identify করা সম্ভব। তাই Roll_No + Student_Name minimal নয়।
সুতরাং, Candidate Key এবং Super Key দুটিই tuple uniquely identify করতে ব্যবহৃত হয়। কিন্তু Candidate Key হলো minimal Super Key, অর্থাৎ এতে কোনো unnecessary attribute থাকে না। অন্যদিকে Super Key minimal নাও হতে পারে এবং এতে extra attribute থাকতে পারে।
তাই বলা যায়, সমস্ত Candidate Key Super Key হলেও সমস্ত Super Key Candidate Key নয়। কারণ Candidate Key হওয়ার জন্য uniqueness-এর পাশাপাশি minimality-ও থাকা আবশ্যক।