0

I want to record some type of user's activity, i.e, a user login, or publish a new post.

I come up two way to do this in database:

1, create an Activity table

activity_type [enum of activity type]
meta_data

use meta_data to store the info of specified activity. But I can only store meta_data as string for objects, and seems not efficient to do query with filter.

2, create a table for every type of activity

# loginActivity
time
ip
# publishActivity
post_id
user_id

The problem of this way is if there is a new type of activity I want to record, a new table should be created.

Which way is more suitable for this situation? Or is there a better way to do this?

dumeng
  • 67
  • 1
  • 5
  • Google re stackoverflow sql/database subtypes/inheritance/polymorphism. Also multiple tables vs one table, and pros & cons of EAV. These are all faqs. PS What is wrong with having tables? That's what databases consist of & what DBMSs manage. – philipxy Jul 27 '18 at 03:47
  • @philipxy I found a good example at [polymorphism-in-sql-database-tables](https://stackoverflow.com/questions/561576/polymorphism-in-sql-database-tables). BTW, having tables is not wrong but when the solution is to create too many tables it made me doubt is it a stupid solution as I do not have much experience in database design :( – dumeng Jul 27 '18 at 08:30

0 Answers0