Explore Library
Code QuizAdvanced

Foreign Key Reference Bug

Spot the schema mistake in a foreign key referencing a non-key column.

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

CREATE TABLE orders (
  id INT PRIMARY KEY,
  customer_email VARCHAR(255),
  amount DECIMAL(10,2),
  FOREIGN KEY (customer_email) REFERENCES customers(email)
);

What is the bug in this schema definition?