Chapter 19. Implementing Referential Integrity and Shared Business Logic

It's not just a black and white issue; there are also shades of gray. Furthermore, last time I looked there's a whole spectrum of colors out there as well.

Referential integrity (RI) refers to the concept that if one entity references another, then that other entity actually exists. For example, if I claim to live in a house at 123 Main Street, then that house must actually be there, otherwise I have an RI error. In relational database design, the referential integrity rule (Halpin 2001) states that each non-null value of a foreign key must match the value of some primary key.

In the 1970s, when relational databases first came on the scene, the standard implementation technology was procedural languages such as PL/1, Fortran, and COBOL. Because these languages didn't implement anything similar to data entities and because the relational database did, it made sense that relational databases were responsible for ensuring RI. Furthermore, relational databases back then were relatively simple: they stored data and supported the ability to implement basic RI constraints. The end result was that business logic was implemented in the application code, and RI was implemented in the database.

Modern software development isn't like that anymore. We now work with implementation languages such as C# and Java that implement entities called classes. As a result, RI also becomes an issue for your application code as well as ...

Get Agile Database Techniques: Effective Strategies for the Agile Software Developer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.