This article is about to create primary key on multiple columns. Go through my previous article here to know about primary key and how to create it.
There are many scenarios where we need to create primary key on multiple columns.
For example, if you take E-learning sites. They are offering free trail and asking us to sign up using our email id and phone number to experience the free trail.
Once trail period is completed then we cannot apply for one more trail using same email id and phone number because the system will not allow inserting same combination again.
Primary key on multiple columns is called “Composite Key”.
Composite Key Syntax:
CREATE TABLE SAMPLE_TABLE
PRIMARY KEY (COL1, COL2));
CREATE TABLE USERS
PRIMARY KEY (EmailId, Phonenumber))