Imagine that I have three entities (EntityA
, EntityB
, EntityC
) that can have some images
. So there are two ways:
Make an image
table for each entity. It means that EntityA
has a image
table named AImages
and similarly for EntityB
and EntityC
.
This method is more intelligent but has more tables.
Have an image
table and another table name EntityType
that 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...