Should your SQL Server database use foreign key constraints?


 

Foreign key constraints exist to stop bad data before it happens, yet plenty of production SQL Server databases run without them. Is that a reasonable trade-off or a ticking time bomb? Greg Low looks at the most common reasons teams skip foreign keys, tests them against real-world experience, and explains why the answer differs for transactional systems versus analytic data warehouses.

Foreign keys are used to ensure referential integrity in relational databases. We don’t want to have orders for customers that don’t exist, or have lines on the orders that refer to products that don’t exist. That seems straightforward enough