Antipattern: Specify Values in the Column Definition
Many people choose to specify the valid data values when they define the column. The column definition is part of the metadataâthe definition of the table structure itself.
For example, you could define a check constraint on the column. This constraint disallows any insert or update that would make the constraint false.
â | âCREATEâ âTABLEâ Bugs ( |
â | â-- other columnsâ |
â | âstatusâ âVARCHARâ(20) âCHECKâ (âstatusâ âINâ (â'NEW'â, â'IN PROGRESS'â, â'FIXED'â)) |
â | ); |
MySQL supports a nonstandard data type called ENUM that restricts the column to a specific set of values.
Get SQL Antipatterns, Volume 1 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.