Z
Z
zlodiak2018-06-30 21:46:24
MySQL
zlodiak, 2018-06-30 21:46:24

How to design a table with a dynamic set of columns?

Help to design the elementary DB please. There is a task to create a multi-user service for recording runners' training in the form of a table.
The table will consist of a mandatory "date" column and a set of columns like: "workout duration, min", "distance, m", "average heart rate, bpm", etc. The number of columns and their names are determined by the user through the UI while working with the service.
I decided to use a relational database like mysql with tables like this:

1. Users:
- primary_key number,
- fname: string,
- lname: string,
- login: string,
- pass_hash: string,
- reg_date_unixstamp: number

2. Columns:
- primary_key: number,
- title: string,
- id_user: foreign_key

3. Values:
- primary_key: number,
- value: string,
- last_update_unixstamp: number,
- id_column: foreign_key,
- id_user: foreign_key

Thus, in the UI, the user, using the datepicker, will select the date interval and the backend will return the result of the query to the Values ​​table. Then, at the front, with the help of simple manipulations, I will draw the server's response in the form of a table.
The problem is that id_user is used in the Values ​​table, and this is redundant because id_user is already in Columns. Please help me redesign the database

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Viktor Yanyshev, 2018-06-30
@zlodiak

column_id for eyes

A
Andrey, 2018-06-30
@VladimirAndreev

Discover json type)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question