An audit finds rows in the Orders table whose CustomerID values do not exist in the Customers table, where CustomerID is the primary key. Which statement prevents new orphaned orders from being created?
Select an answer to reveal the explanation.
Short Explanation
Give the table a foreign key and you've hired a bouncer for the door: no order gets in unless its customer is already on the guest list. NOT NULL just checks that a name was written down, not that the person exists. And watch out, that UNIQUE constraint would stop a customer from ever placing a second order.
Full Explanation
Referential integrity requires that a value in a referencing column match an existing value in the referenced key. A FOREIGN KEY constraint on Orders.CustomerID that REFERENCES Customers(CustomerID) makes the engine reject any insert or update in Orders that names a nonexistent customer, and by default it also rejects deleting a customer who still has orders. A UNIQUE constraint on Orders.CustomerID enforces that each value appears only once in Orders, which would block a customer from placing more than one order and still says nothing about whether the customer exists. Setting the column NOT NULL guarantees a value is present but accepts any value, including one with no matching customer. Creating an index on CustomerID speeds joins and lookups and is commonly added alongside a foreign key, but an ordinary index enforces no rule at all. Exam caveat: adding the foreign key will fail, or in some engines be created as not validated, while existing orphan rows remain, so the existing data must be cleaned or reconciled first. Operational check: run an anti-join such as a LEFT JOIN from Orders to Customers filtered on a NULL customer key to list orphans, resolve them, add the constraint, and then test that an insert with an invalid CustomerID is rejected.