Learn VisualLearn DB

Protect the Final Stored State

An invariant is a condition that accepted database states must satisfy. PRIMARY KEY and UNIQUE protect identity (for example, products.id), NOT NULL protects required values (for example, qty), CHECK protects conditions on a row (for example, price >= 0), and FOREIGN KEY protects references (for example, orders.customer_id). Application validation improves the interaction, but database constraints cover every writer.

GOAL

Select constraints for identity, required values, valid ranges, and references.

Which two constraints express that every order quantity exists and is greater than zero?