How to Recognize the Antipattern
The problems with using ENUM or a check constraint arise when the set of values is not fixed. If you’re considering using ENUM, first ask yourself whether the set of values are expected to change or even whether they might change. If so, it’s probably not a good time to employ an ENUM.
-
“We have to take the database offline so we can add a new choice in one of our application’s menus. It should take no more than thirty minutes, if all goes well.”
This is a sign that a set of values is baked into the definition of a column. You should never need to interrupt service for a change like this.
-
“The status column can have one of the following values. We should not need to revise this list.”
Shouldn’t need to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access