MySQL + SQL · Lesson 19
Composite Key and Unique Key
What is a Composite Key?
A composite key is a primary key made of TWO OR MORE columns together. Used when no single column is unique on its own.
Example
CREATE TABLE marks (
roll_no INT,
subject VARCHAR(20),
score INT,
PRIMARY KEY (roll_no, subject)
);Neither roll_no nor subject is unique alone, but together they uniquely identify a row.
Summary
- A composite key combines multiple columns as the primary key.
- Used when one column alone cannot uniquely identify a row.
💻 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ें.