I have a table called users, and one of the rows needs to hold all the actions the user did, and the actions are referenced as action_ids.
How do I have the row hold multiple action_ids?
For example, lets say the user did 5 actions, each with IDs 100001, 100002, 100003, 100004, 100005. How do I store that into the database so I can later say all the actions a user did?
The row might have to store hundreds or thousands of 6 digit values.
I would recommend you create a
UserActiontable with aUserIdandActionId. This way you could reference the actions done without having to store multiple values in one row of youruserstable.You would store rows for each action a user takes. The table might look like this:
Results:
Meaning that UserId = 1 performed actions 100001, 100002 and 100007 and UserId 2 performed 100002 and 100003
Doing this also helps preserve normalization for your database, making future queries easier as well.
You will be able to find how many actions have been performed by users easier (and other tasks) with this structure than parsing a column with text/string values: (I’m assuming you have a Name, or similar field)
Also, if I were making the table, I would add
UserActionIdas an Auto-incremental Id column to use as myPrimary Key