I have three tables like this.
location(id,name)
tour(id,name)
hotel(id,name)
above three tables(location, tour and hotel) has many images.
So the traditional way to store the images would be
location_images(id,image_url,location_id)
tour_images(id,image_url,tour_id)
hotel_images(id,image_url,hotel_id)
Instead of keeping images in three different tables like this can I make one table for store all three types of images like this?
images(id,image_url,type,foreign_key)
How do I achieve this using MySQL?
How do I make my foreign_key
connect with the type
?
I am using MySQL 5.7.24-0ubuntu0.18.04.1 (Ubuntu)