Chapter 6. Constraints and Predicates

With integrity and consistency—your credits are piling up.

message in a Chinese fortune cookie (November 15th, 2004)

Constraints and predicates are distinct but related concepts in the database world. They’re also both extremely important! Constraints have to do with making sure the data in the database is correct, and predicates have to do with what that data means. Let’s take a closer look.

Database constraints

I first mentioned database constraints in Chapter 3, though in that chapter I called them integrity constraints. A database constraint, or just a constraint for short, is, loosely, a boolean expression that must evaluate to TRUE (because if it evaluates to FALSE, there must be something wrong with the database). Thus, any attempt to update the database in such a way as to cause some constraint to evaluate to FALSE must fail—and, in the relational model, fail immediately, meaning the exception must be raised as soon as the update is attempted.[41] Note: This requirement (that constraint violations be detected immediately) is sometimes referred to as The Golden Rule. Observe that it’s an immediate consequence of this rule that no user ever sees the database in an inconsistent state—where an inconsistent state is, by definition, a state of the database that violates at least one known constraint. Observe further that an inconsistent state is certainly an incorrect state, in the sense that it can’t possibly correspond to a true state of affairs ...

Get Relational Theory for Computer Professionals 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.