SQL Keys ka Funda

Understand how SQL Keys works with Fullstackgada

๐Ÿ”‘ SQL Keys Explorer

Bhide ki Uljhan: SQL mein itni saari keys hain! Samajhte hain kaun si key kab kaam aati hai.
SQL Keys Kya Hain?
Keys database mein records ko uniquely identify karne ke liye use hoti hain. Kisi bhi key type pe click karo!

๐ŸŽญ Jethalal ki Samjhaish

Jethalal ka Style: Gokuldham Society ke examples se database keys samjhaate hain!

๐Ÿ  Gokuldham Society Analogy

๐Ÿค”
Kaun si key ke baare mein jaanna chahte ho? Upar se select karo!

๐ŸŽฎ Interactive Example

Koi key type select karo toh interactive example dekho...

๐Ÿ“Š Visual SQL Keys Demonstration

๐Ÿ‘จโ€๐ŸŽ“ Students Table Example

๐Ÿ—๏ธ StudentID (PK) Naam Email ๐Ÿ”„ AadharNo (AK) Phone
101 Jethalal jethalal@gokuldham.com 1234-5678-9012 9876543210
102 Bhide bhide@discipline.com 2345-6789-0123 8765432109
103 Popatlal popat@reporter.com 3456-7890-1234 7654321098
Key Points:
๐Ÿ—๏ธ Primary Key: StudentID - Har student ko uniquely identify karta hai
๐Ÿ”„ Alternate Key: AadharNo - Yeh bhi unique hai par Primary nahi bana
๐ŸŽฏ Candidate Keys: StudentID, Email, AadharNo - Sabhi unique identifiers hain

๐Ÿ“š Enrollment Table Example

๐Ÿงฉ StudentID (CK) ๐Ÿงฉ SubjectCode (CK) Grade Semester
101 MATH101 A 1
101 PHY101 B+ 1
102 MATH101 A+ 1
Key Points:
๐Ÿงฉ Composite Key: (StudentID + SubjectCode) - Dono milkar unique pehchaan
๐Ÿ”— Foreign Key: StudentID - Students table ke Primary Key se linked
๐Ÿฆธ Super Key: (StudentID + SubjectCode + Grade) - Extra column ke saath bhi unique

๐Ÿ”— Table Relationships Visualization

/* Students Table */
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Email VARCHAR(100) UNIQUE,
AadharNo VARCHAR(12) UNIQUE
);
/* Enrollment Table */
CREATE TABLE Enrollment (
StudentID INT,
SubjectCode VARCHAR(10),
Grade VARCHAR(5),
PRIMARY KEY (StudentID, SubjectCode),
FOREIGN KEY (StudentID) REFERENCES Students(StudentID)
);

๐Ÿ” SQL Keys ki Takkar

Key Type Definition Properties Jethalal ki Analogy
๐Ÿ—๏ธ Primary Key Har record ko uniquely identify karti hai Not NULL, Unique, Ek table mein ek hi Secretary ki seat - Sirf ek hi banda ho sakta hai
๐Ÿ”— Foreign Key Ek table ke Primary Key se link karti hai NULL ho sakti hai, Referential integrity maintain karti hai Madhvi se tera rishta hai
๐ŸŽฏ Candidate Key Koi bhi column jo records ko uniquely identify kar sake Ek table mein multiple, Unique, Minimal Secretary banne ke eligible candidates
๐Ÿงฉ Composite Key Do ya zyada columns ka combination Sath mein unique, Individually unique nahi bhi ho sakte Teri shaadi - Tu + Madhvi bhabhi dono chahiye
๐Ÿฆธ Super Key Koi bhi combination jo uniquely identify kare Extra unnecessary columns ho sakte hain Sakharam ka papa + Secretary = Bhide
๐Ÿ”„ Alternate Key Candidate Key jo Primary nahi bani Unique par Primary nahi chuni gayi Babita ji bhi candidate thi - par Alternate ban gayi