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.
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

WhatsApp