3

I'm making the tables for an application, and I need many tables with images.

Instead of storing the BLOBS on each table, I'm thinking on storing all the images (BLOB) on a single table, to unify the processing of all images with a small set of routines.

I'm not asking if I should store the images on a table made only for images. I'm asking if I should use a single table for all the images, or multiple tables holding images. (For example, one tables for images of employees, and other for images of cars).

I'm inclined to use a single table for all images. But I have zero experience with databases, and I don't know if it is a good idea. Maybe it breaks normal forms rules?

timix
  • 51
  • 3
  • 3
    Possible duplicate of [Creating a separate table for images or adding "image fields" to many tables?](https://softwareengineering.stackexchange.com/questions/264779/creating-a-separate-table-for-images-or-adding-image-fields-to-many-tables) – gnat Dec 26 '17 at 13:06
  • 3
    Is there any reason you need to store the images themselves in the database? There may well be a good reason, but some advice I received once when trying to do this was "use the database for *data*, and use the filesystem for *files*. You can store the images in the filesystem and just save the file path in the database to link to it. – neilsimp1 Dec 26 '17 at 13:22
  • @gnat I think that is a different question. I'm asking how many image tables should use, not if I should use them or not. – timix Dec 26 '17 at 13:44
  • @neilsimp1 Your advice is probably a good idea, but at this point I do not know how to keep the file synchronized with the record on a table. – timix Dec 26 '17 at 14:01
  • 1
    It depends. Which is the use pattern of these data by your application ? Will you be performing updates frequently ? Will you be adding data at the same time while you delete data ? Will you be processing these images somehow ? Forget the fact that you're dealing with images, but focus on the fact that you're dealing with sets of data. – Machado Dec 26 '17 at 16:06

1 Answers1

2

The single table approach sounds reasonable. Keeping them all over the database in different tables may become difficult to manage, and you may end up with a lot of duplicate code that does basically the same thing, just against different tables.

(That said, if you have a large number of images, say > 10,000, I'd certainly consider both a single table to track the images, and keeping the images themselves in the file system. This way you are not using the database connection to handle the transfer of the images)

GrandmasterB
  • 37,990
  • 7
  • 78
  • 131