Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Database design problem

I am designing a database for an application where a user can comment on pictures & videos.

Should I keep separate tables for comments like (Picture_comments & videos_comments)
OR
should I keep single table for comment and other mapping tables like (picture_comment_mapping & video_comment_mapping).

Which one will be better approach and why?

Detail
Approach 1:

user
     id
     name

Picture
     id
     link
video
     id
     link

comment_video
     id
     user_id
     video_id
     comment
comment_picture
     id
     user_id
     picture_id
     comment

Approach 2:

user
     id
     name

picture
     id
     link
video
     id
     link

comment
     id
     user_id
     comment

comment_picture_mapping
     id
     comment_id
     picture_id
comment_video_mapping
     id
     comment_id
     video_id

Which one is better approach and why?

like image 519
Rahul Prasad Avatar asked Jan 26 '26 06:01

Rahul Prasad


1 Answers

I would use your approach number 2 because its much easier to then do things like "Search all comments"

like image 191
Matt Avatar answered Jan 28 '26 23:01

Matt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!