Reputation: 29
I am building a database for my application using Mysql, contains 2 tables in which one table will have user details and other table will have all user's activities(say posts,comments,..). I have 2 approaches for this PS.
If we go with approach 1, it builds time complexity in case of more users. with approach 2, eats up database. which design will show less time and space complexity?
Upvotes: 1
Views: 173
Reputation: 8496
For better database maintain, you have to go with the first approach because you can normalize data easily.. and the perfect way to manage database structure, Need to take care of below points
user_id
field for fast result in join query.user_activities_archive
for store old activities. in the regular period, you can move an old record from user_activities
to user_activities_archive
user_posts
, user_comments
instead of user_Activities
for more splitting data and different structures of the table, for example you can manage replyto_id
in the comment table and user_post
table might have title field.In the second approach for cerate tables for each user, there are many limitations like
Upvotes: 1
Reputation: 69
As juergen d mentioned in the comment, approach 2 should not be used. However I would consider splitting useractivities into different tables if the possible user activites are different from each other to avoid unneccessary column.
Example: A comment table with information about who made the comment (foreign key to user table) and the comment itself. + A foreign key to another user activity to wich the comment was made.
The comment column in the above table does not make sence for say, just a like of a post, so I would have created a different table for likes.
Upvotes: 0