Let me give you a bit context first, before I list down my questions.
I am using python, tkinter and MySQL for my project. I have 2 tables in my database timetablebtn
whose fields are:
----------------------------------------------------------
Field | Type | Null | Key | Default | Extra |
----------+---------------+------+-----+---------+--------
sno | int(5) | NO | PRI | 0 | |
btnobject | varchar(50) | NO | | NULL | |
tabledate | varchar(20) | NO | | NULL | |
----------------------------------------------------------
An example record for the above would be: 1,"btnobject1","01/01/21"
, 2,"btnobject2","02/01/21
which I would achieve using the following sql command
INSERT INTO timetablebtn VALUES (1,"btnobject1","01/01/21");
and there are 24 such records in this table.
and timtableevents
:
------------------------------------------------------
Field | Type | Null | Key | Default | Extra |
-------+--------------+------+-----+---------+-------+
sno | int(5) | NO | PRI | 0 | |
time | varchar(20) | NO | | NULL | |
events | varchar(100) | NO | | NULL | |
------------------------------------------------------
An example of this record would be: 1,"07:30-08:30","Exercise"
What I want is that each btnobject
in the timetablebtn
table be referencing to a different instance of timetablevents
,i.e. I want each btnobject to have their own timetablevents without me manually creating each table as creating 24 tables is a lot of work.
OR
I want btnobject to be a foreign key where the structure of a new table would be:
---------------------------------------------
btnobject | sno | time | events |
-----------+-----+-------------+------------+
btnobject1 | 1 | 07:30-08:30 | Exercise |
| 2 | 08:30-09:00 | Breakfast |
| 3 | 09:00-11:00 | HackerRank |
btnobject2 | 1 | 07:30-08:30 | Exercise |
| 2 | 08:30-09:00 | Breakfast |
| 3 | 09:00-11:00 | Read books |
---------------------------------------------
OR
Create a table with btnobject as a foreign key where table structure would be:
--------------------
btnobject | details
-----------+--------
btnobject1 | {'sno':[1,2,3],'time':['07:30-08:30','08:30-09:00','09:00-11:00'],'events':['Exercise','Breakfast','HackerRank'] }
btnobject2 | {'sno':[1,2,3],'time':['07:30-08:30','08:30-09:00','09:00-11:00'],'events':['Exercise','Breakfast','Read books'] }
where the elements under the details
column is a python dictionary.
Is there any way to achieve this?
OR
If there is a better way than what I have listed above, then Please do share it with me. Thanks in advance.