MySQL + SQL · Lesson 1
Dbms Keys Explained
All Keys in One Place
This page summarizes every key type in DBMS with a single clear example.
Every Key Type
| Key | One-line Meaning |
|---|---|
| Super key | Any unique-identifying column set |
| Candidate key | Minimal super key |
| Primary key | Chosen main identifier (unique, not null) |
| Alternate key | Candidate keys not chosen primary |
| Foreign key | Refers to another table's primary key |
| Composite key | Made of multiple columns |
School Example
students(roll_no PK, admission_no UNIQUE, name)
marks(roll_no FK, subject, score, PRIMARY KEY(roll_no, subject))marks uses a COMPOSITE primary key (roll_no + subject) and roll_no is a FOREIGN key.
Summary
- Keys: super, candidate, primary, alternate, foreign, composite.
- Composite keys combine columns; foreign keys link tables.
💻 Live Code Editor
Is page ki language (MYSQL) mein code likhein aur turant chalाएं — yahीं, bina kuch install kiye.Powered by OneCompiler. Agar editor na khule to yahान naye tab mein kholein.
💻 Live Code Editor
Is page ke program yahan ready hain — chalाएं, badlें aur seekhें. Bina kuch install kiye.
Powered by OneCompiler. Editor mein code apne aap aa jata hai — Run dabaakर output dekhें.
Agar load na ho to naye tab mein kholें.