Primary Keys, Foreign Keys & Data Integrity

A primary key uniquely identifies each record in a table. Its values must not be duplicated or missing. A person's name is usually unsuitable because different people can share a name. A unique MemberID is more dependable.

Worked example

Two records have Name="Alex Lee" but MemberID values 104 and 105. The keys are unique even though the names match. A key constraint prevents duplicate key values; it does not prove the two records describe different real people.

Validation checks whether input meets a rule, not whether it is true. A presence check can require a name, a range check can limit age, and a format check can check the layout of an identifier. A validly formatted wrong date may still pass.

Independent design

Choose a primary key for a school library's books when several copies share a title. Explain why a separate copy identifier is needed. Choose a validation rule for a publication year and explain one incorrect value that could still pass it.

This course's core database tasks use a single table. Multiple-table relationships and advanced key taxonomy are optional later study.

AI Socratic Tutor

All-Access
Sign in or create an account. AI Tutor is an All-Access benefit.
Sign Up

Need guidance? Ask a question or use the hint below.

AI Socratic Tutor is an All-Access Benefit

Unlock step-by-step Socratic hints, algorithm trace table walkthroughs, and error diagnostics for every Cambridge exercise.

You're chatting with an AI tutor, not a person. AI can make mistakes, so double-check its answers.

Independent Practice: Choose a key

+30 XP

Independent Practice: Choose a key

  1. Two members can share a name. Is Name guaranteed unique: yes or no? [Space 1]
  2. Should a primary key allow duplicate values: yes or no? [Space 2]
  3. Should a primary key be missing: yes or no? [Space 3]
Word Bank / Available Cards (Drag into spaces or tap to place)
All-Access Required

Interactive exercises for Module 2 and beyond require an active plan.