Interview Question

What is a composite key?

A composite key identifies rows through a combination of columns.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

A composite key uses more than one column to identify or constrain a row. • The uniqueness rule applies to the column combination. • It is useful when no single column identifies the relationship. • Foreign keys referencing it must use compatible referenced columns.

💡 SQL Example

CREATE TABLE enrollments (student_id integer, course_id integer, PRIMARY KEY (student_id, course_id));

Result

CREATE TABLE

⚡ Quick Revision

A composite key identifies rows through a combination of columns.