Antipattern: Create Multiple Columns
You still have to account for multiple values in the attribute, but the new solution must store only a single value in each column. It might seem natural to create multiple columns in this table, each containing a single tag.
â | âCREATEâ âTABLEâ Bugs ( |
â | bug_id âSERIALâ âPRIMARYâ âKEYâ, |
â | description âVARCHARâ(1000), |
â | tag1 âVARCHARâ(20), |
â | tag2 âVARCHARâ(20), |
â | tag3 âVARCHARâ(20) |
â | ); |
As you assign tags to a given bug, youâd put values in one of these three columns. Unused columns remain null.
â | âUPDATEâ Bugs âSETâ tag2 = â'performance'â âWHEREâ bug_id = 3456; |
bug_id |
---|
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.