CompTIA DataSys+ (DS0-001)Database FundamentalsEasy

A developer is writing a script to insert new customer records into a `Customers` table. Each customer record must include a unique `CustomerID`. Which SQL Data Definition Language (DDL) constraint ensures that no two customer records can have the same `CustomerID`?

  1. ANOT NULL
  2. BFOREIGN KEY
  3. CPRIMARY KEY
  4. DCHECK
Show answer & explanation

Correct answer: C. PRIMARY KEY

A PRIMARY KEY constraint uniquely identifies each record in a table and automatically enforces a NOT NULL constraint. This ensures that every customer will have a unique and non-empty CustomerID.

Why the other options are wrong

  • A. NOT NULL ensures that a column cannot contain a NULL value but does not enforce uniqueness.
  • B. FOREIGN KEY establishes a link between two tables, enforcing referential integrity.
  • D. CHECK enforces that all values in a column satisfy a specific condition.

PRIMARY KEY

A column or set of columns in a table that uniquely identifies each row in that table.

  • Must contain unique values.
  • Cannot contain NULL values (implicitly NOT NULL).
  • A table can have only one primary key.

Memory trick: Primary keys are the unique ID badges of your data.

More Database Fundamentals questions