how to add a new column every time i run a python program

元气小坏坏 提交于 2019-12-02 09:17:16

Don't change your DB design at runtime, but design it in a way that you will change the data not the structure.

You could have two tables. One called Student with columns rollno and name, maybe PK on rollno if it is unique.

Then have another table called Thing (any suitable name, but I don't know what your data is about) with three columns when (datetime), value (any suitable name) (CHAR(1)) and student (same type as rollno).

Define PK over both when and value to ensure that each student has only one value per date. Define a FK from Thing.student to Student.rollno. Now your DB takes care of keeping your data (mostly) consistent.

Define indices depending on your needs of selects, inserts and updates over the different columns.

Then for querying join both tables to get the desired result, e.g.

select s.name, t.value
from Student s
left join Thing t on t.student = s.rollno
where t.when == 'whenever'

(I am not sure about the mysql dialect, so maybe some more quotes are needed. Please feel free to edit.)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!