O'Reilly logo

Relational Theory for Computer Professionals by Chris Date

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required