Easy Database Systems Database Design
What is the difference between UNIQUE and PRIMARY KEY constraints?
Answer
Both ensure uniqueness, but PRIMARY KEY also enforces NOT NULL and only one is allowed per table - it defines the main identifier for rows. UNIQUE allows NULL values (one null per column in most databases) and multiple UNIQUE constraints can exist on a table. PRIMARY KEY typically creates a clustered index (physical row ordering), while UNIQUE creates a non-clustered index. Use PRIMARY KEY for main identifier, UNIQUE for alternate keys.
IIT Certified
Master These Concepts with IIT Certification
175+ hours of industry projects. Get placed at Bosch, Tata Motors, L&T and 500+ companies.
Relevant for Roles
Software Engineer Backend Developer Database Developer