Search code examples
relational-databasedatabase-schemaentity-relationshipimageurl

Image urls in entity diagram


For a car retail system database, I will draw entity relationship diagram. I need a suggestion for keeping image urls as data.
For instance, should I define image attributes in every entities? Like;

In car model: carId carName carImage

In carSeller model: carSellerId carSellerName carSellerImage,

or

How should I define relation if it is defined as different entity? like:

in car model: carId carName ImageId(foreign) in carSeller model: carSellerId carSellerName``ImageId(foreign) in Image Model: ImageId ImageURL

or Should I create different database? because there will be lots of entities that relates to image entity.

What is the best way doing it?


Solution

  • It depends on your task. If you are going for One-to-One relation between image and car to give only one picture of the car, you can make image url a car's attribute, like in your 1st alternative.

    If you want to give several images of one car, you are going for Many-to-One relation, and end up with table like (image_id,image_url,car_id (fk)). Another option is to use array datatype for car's images column, if your DBMS supports such feature.

    And if you want to share pictures between similar cars, you need to implement a Many-to-Many relation with two tables: (image_id,image_url) plus (image_id (fk), car_id (fk)).