Define Candidate Key and Unique Key
In : IMCA Subject : Introduction to RDBMSA Candidate Key is a column or a combination of columns in a table that can uniquely identify each row in that table. It must contain unique values and cannot contain nulls. There can be more than one candidate key in a table, but only one of them becomes the Primary Key .
A Unique Key , on the other hand, is a constraint that ensures all the values in a column (or a set of columns) are unique across the table. Unlike a candidate key, a unique key can allow one null value (depending on the RDBMS), and it is often used to enforce uniqueness for data that isn’t necessarily the primary key.
CREATE TABLE Students (
StudentID INT PRIMARY KEY, -- Primary Key (chosen from candidate keys)
Email VARCHAR(100) UNIQUE, -- Unique Key constraint
AadharNumber VARCHAR(12) UNIQUE, -- Another Unique Key (could be a candidate key)
Name VARCHAR(100),
PhoneNumber VARCHAR(15)
);