ITP

IMCA - Introduction to RDBMS

Define Candidate Key and Unique Key

In : IMCA Subject : Introduction to RDBMS

A 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)
);

About us

A truly open platform where you may ask questions and get answers. We also provide comprehensive and easy-to-understand answers to question papers.  discover...

Site status

Flag Counter

Privacy Policy

Sitemap