S
S
Sergey Savostin2016-06-12 18:47:05
MySQL
Sergey Savostin, 2016-06-12 18:47:05

How to organize a DB in this case?

It is necessary to create a table to store "actions" of users (user_id) on "subjects".
The subject can be one of several IDs of different kinds, with different parameters of its own.
Well, for example:
Table subj1: subj_1_id, subj1_name, subj1_param1, ..., subj1_paramN
Table subj2: subj_2_id, subj2_name, subj2_param2, ..., subj2_paramM
, etc.
In the action table, you need to store the user_id, the action type (enum), some set of action parameters that is the same for all actions, and the subject id (subj1_id or subj2_id or...).
How is it better to compile this table so that, say, FOREIGN KEY works, there is no confusion with the subject ID, data integrity, etc. beauty? It is somehow ugly to make a separate table for each subj, and then with UNION you are tormented to get, say, a list of all user actions. For each subj its own column? It's kind of irrational too.
Who does what?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question