When creating a many to many table, relational database. If for example you are enabling users to scrape images form around the web and tag them.
Would it be better to:
-
Check to see if the image is already in the database and if it is, create a link in a relational table and if it is not create a new image.
-
Create a unique instance of the image for every user and when looking to display the most popular images SELECT AND ORDER BY the image with the most duplicates
I hope this makes sense. Thanks in advance for you help.
I assume you have something equivalent to a
USERStable and aPICTUREStable. Also a table to break up the many to many relationship.U2PI will call it.The option you listed as option 1 would seem to be the preferred way. Check to see if the picture is in the DB, if it is get primary key from
PICTUREScorresponding to it. If not, put the picture in thePICTUREStable.Regardless of if it is a new image, or one that is already in there, you will insert the event into the
U2Ptable. This would reference theUSERSprimary key and thePICTURESprimary key corresponding to the event. You would also record other data such as time etc…