Antipattern: Assume You Must Use Files
Conceptually, an image is an attribute in a table. For example, the Accounts table may have a portrait_image column.
â | âCREATEâ âTABLEâ Accounts ( |
â | account_id âSERIALâ âPRIMARYâ âKEYâ, |
â | account_name âVARCHARâ(20), |
â | portrait_image âBLOBâ |
â | ); |
Likewise, you can store multiple images of the same type in a dependent table. For example, a bug may have multiple screenshots that illustrate it.
â | âCREATEâ âTABLEâ Screenshots ( |
â | image_id âSERIALâ âNOTâ âNULLâ, |
â | bug_id âBIGINTâ âUNSIGNEDâ âNOTâ âNULLâ, |
â | screenshot_image âBLOBâ, |
â | caption ... |
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.