Explore Library
Code QuizAdvanced

Foreign Key Referencing Wrong Column

Spot the schema design bug in a foreign key that references a non-key column.

Codesql
CREATE TABLE customers (
  id INT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(255)
);

CREATE TABLE orders (
  id INT PRIMARY KEY,
  customer_id INT NOT NULL,
  total DECIMAL(10,2),
  FOREIGN KEY (customer_id) REFERENCES customers(name)
);

What is the bug in this schema definition?