SQL Composite Key

A Composite Key is a Primary Key made up of two or more columns that together uniquely identify each record in a table.
👉 It is used when a single column is not enough to uniquely identify a row.

Key Idea
   • One column alone cannot uniquely identify the row
   • But multiple columns together can
Those combined columns form a Composite Key.

CREATE TABLE StudentCourses (
    Student_ID INT,
    Course_ID VARCHAR(10),
    Grade CHAR(1),
    PRIMARY KEY (Student_ID, Course_ID)
);


Explanation:
Student_ID + Course_ID together form the Composite Primary Key.


Simple Definition
👉 A Composite Key is a primary key formed by combining two or more columns to uniquely identify a record.


Topics