views:

113

answers:

3

Ok, so my site is centric to a lot of dynamic user entered images for different user defined objects throughout. So I have many objects, and those objects have images.

Is it good practice to treat images like an object since the "Image Name" and "Image Bytes" columns are repeated many times? Or is it more sensible just to include those two columns in the tables for each object.

I guess I'm answering my own question while typing... I am creating an extra join and an extra column (there would be three with Name, Id, and ImageId on each table"

however, there are several tables with multiple images per object... so I guess it would be better???? Opinions?

+4  A: 

I generally have a Files table that stores files more generically. Then in your other tables, you could have a column for each image (file) which is just a reference into the files table.

Your files table would have all the normal stuff like ID, Filename, Size, type, etc. Then yes, you'd just join into it to get what you need for whatever query you're running.

In case there is any doubt--I'd strongly discourage you from storing files directly in the database. I don't think that's what your after but if anyone else gets that idea--just don't do it!

Michael Haren
A: 

The question to ask is "do I have multiple objects with the same image." If so, then you might want to think about redundancy. Also, does the data base you're using handle "blobs" well? Or would it be better to keep a file path to the image and store the images separately>

Charlie Martin
A: 

Intuitively, I would find it easier to deal with the images and objects as separate concepts. It just feels more flexible.

If you need to attach things other than images to particular objects, it becomes as simple as associating the object table entry with the "other things" table entry, although you'd probably have to swap which way the foreign key pointed. It would also give you the ability to use those images in other user objects, or to allow users to borrow other users images.

The downside to this approach is you would pay a bit of a performance penalty for needing to join one or more tables together. Probably not the biggest deal, though, if your databases query analyzer is reasonably smart.

Ed Carrel