I'm not too sure how to word my question, but here it is.
Let's say I have multiple tables, dogs
, cats
, and birds
. Each of them have uploads
related to them. Each can have many, so I figured it would be best to be on its own table.
Which is a better approach?
uploads
table with for
taking the table (say dogs
), and for_id
referencing the id of that column uploads
table with a columns dogs_id
, cats_id
, birds_id
, with one of them filled with the relative id uploads_dogs
, uploads_cats
and uploads_birds
Or maybe there is a better appraoch?
Thank you!
You could use a single uploads table with a type id (birds = 1, cats = 2, etc.) and an object id column containing the ID of the cat/bird/dog. So when you want to find all uploads for a given cat:
SELECT * FROM uploads WHERE typeId = 2 AND objectId = [catId]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.