PGoCareerGoCareer prep tools
LoginSign up
  • Java
  • Python
  • AI
  • React
  • Angular
  • PHP
  • Node.js
  • SQL
  • DSA
  • HTML
  • CSS
  • JS
  • Spring
  • ML
  • MongoDB

SQL · Theory

Primary Key vs Candidate Key

← All stacks

Theory

271/439

Primary Key vs Candidate Key

A candidate key is any column set that could be the PK (unique + not null). You pick one candidate as the PRIMARY KEY. The others stay UNIQUE (alternate keys). roll and (aadhaar) might both be candidates — you pick roll as PK and UNIQUE on aadhaar.

This is theory (DBMS textbooks). In MySQL you implement: one PRIMARY KEY, other candidates as UNIQUE NOT NULL.

Trap — reciting ‘candidate key’ without an example table.

On the example next to this theory: Primary Key vs Candidate Key — keys and constraints protect data integrity; indexes speed lookups.

Diagram
  students.id  ← PK (unique)
       ▲
       │ FK
  marks.student_id
Exam tip

Candidates: roll or aadhaar. Pick one PK, UNIQUE the other.

Primary Key vs Candidate Key — sample query

CREATE TABLE authors (
  id INTEGER PRIMARY KEY,
  email TEXT UNIQUE NOT NULL
);
CREATE TABLE books (
  id INTEGER PRIMARY KEY,
  author_id INTEGER NOT NULL,
  title TEXT NOT NULL,
  FOREIGN KEY (author_id) REFERENCES authors(id)
);
INSERT INTO authors VALUES (1, 'a@x.com');
INSERT INTO books VALUES (1, 1, 'SQL Basics');
SELECT * FROM books;

Primary Key vs Candidate Key — keys and constraints protect data integrity; indexes speed lookups.

Short notes

  • DefCandidate = could be PK. One candidate is chosen as PK.
  • RuleOther candidates → UNIQUE NOT NULL.
  • TrapTheory without a students example.

Questions

1

Candidate vs primary?

271 / 439

P

GoCareerGo

Utilities · Preparation Hub · Resume · CV · Tools — one workspace.

Workspace

DashboardProfilePreparation HubResume builderCV builderCareer planning

PDF Tools

Merge PDFSplit PDFCompress PDFImage to PDFAll toolsJobs

Image & QR

Compress ImageResize ImageQR ScannerQR GeneratorBlogIT interview prep

Company

FAQFeedbackContactPrivacyTermsSitemap

© 2026 GoCareerGo. Keep moving forward.