Let me explain this ambiguous question. I’m using MySQL and I’m noob in database design, in my business logic I want to store every day, hours and and label each minute in the database for years for each user, something like User1-2024_7_27-20:01-S
:
- User1 is the user id
- 2024_7_27 is the date for a specific day
- 20:01 is the specific hour and minute in that day
- S is a label for “Sleep”, user1 can label themselves as Sleeping at that specific time and date.
So I have User
table with UID as PK, and User-Tracker
table with composite PK UID and DateID for Date and time for each hour in a day. Now I need to know which approach is the best to store the Minutes for each day, it is either:
- Design the
User-Tracker
table to store 1440 rows per day (number of minutes per day) for each user with an attribute char(1) Label, which is gonna enlarge the amount of rows x60 but we get advantage of simple DB queries for CRUD-ing a specific minute.
User-Tracker
table:
CREATE TABLE UserTracker (
UID VARCHAR(255),
DateID DATETIME DEFAULT CURRENT_TIMESTAMP, --Year-Day-Minute, 1440 rows per day for each user
Label CHAR(1), --one character label for each specific minute
PRIMARY KEY (UID, DateID)
);
Then creating stored procedure to trigger the table to create new 1440 rows (number of minutes in a day) for each user every new day!!
- Design the
User-Tracker
table to store 24 rows per day (number of hours per day) for each user with an attribute varchar(60) MinutesLabels which labels each row (hour) where each character of the 60 chars is a label for each minute consecutively; something like ‘SSSSSS…BBBBBB’ (30 S character and 30 B character, S for Sleep and B for Breakfast; in that specific hour (row) the first 30 minutes was sleeping and second 30 was eating breakfast), which will add extra steps for programmers to CRUD a specific minute (they need to Read the MinutesLabels for a specific hour in of a specific day then parse the string and read/edit it by index).
User-Tracker
table:
CREATE TABLE UserTracker (
UID VARCHAR(255),
DateID DATETIME, -- Year-Day, only 24 rows per day for each user
Label VARCHAR(60), -- 60 characters each character labels a minute consecutively by index
PRIMARY KEY (UID, DateID)
);
Then creating stored procedure to trigger the table to create new 24 rows for each user every new day.
- A better approach i don’t know xd.
It is going to be a lot of CRUD operations on that User-Tracker
table and most of them are minutes wise, note that most operations are going to be on multiple minutes per operation and I’m concerning how valid it is to enlarge data x60 for each day for multiple years for huge amount of users +100,000. Do I make it easier for programmers with the cost of extra space and multiple rows edits for each query or save more space with the cost of extra lines of code parsing strings?
Or maybe I’m missing something!?