Imagine that I have three entities (EntityA, EntityB, EntityC) that can have some images. So there are two ways:
Make an
imagetable for each entity. It means thatEntityAhas aimagetable namedAImagesand similarly forEntityBandEntityC. This method is more intelligent but has more tables.Have an
imagetable and another table nameEntityTypethat goes between.
EntityType table has an EntityTypeId column and a name and has three records: 1,EntityA, 2,EntityB, 3,EntityC.
Then in image table:
If I save a record for EntityA the record in image table would be this: 1,1,name
First column is ImageId, second one is EntityTypeId and the third one is image's filename.
If I save a record for EntityB the record in image table would be this: 2,2,name
And if I save a record for EntityA the record in image table would be this: 3,3,name
In this method the number of tables would decrease but the queries would be longer.
Which one is optimised or any other way...
