简体   繁体   English

用日期列创建MySQL表

[英]create MySQL table with date columns

I want to create MySQL table to manage registration of students. 我想创建MySQL表来管理学生的注册。 the name of the table its the course name and inside of it there is the first column : student_id and after that i want column for each date in the semester that course takes place. 表的名称及其课程名称,表的第一student_idstudent_id ,此后我希望该课程发生的学期中的每个日期都具有该列。

so for example if course takes place every sunday and monday between 1st to 9th of March than i will have column's like this: |01/03/2016|02/03/2016|08/03/2016|09/03/2016 因此,例如,如果课程在3月1日至9日之间的每个星期日和星期一进行,那么我的专栏应为: |01/03/2016|02/03/2016|08/03/2016|09/03/2016

i'm taking first steps with MySQL and got to hear about PROCEDURE but not sure if that's what i need or there's a better way to achieve that 我正在使用MySQL迈出第一步,并了解了PROCEDURE但是不确定这是否是我所需要的,或者有更好的方法来实现这一目标

This does not sound like a good way to structure your database... 听起来这不是构建数据库的好方法。

The "best" way to represent your data in a relational database depends on your specific use-cases (as well as potential future use-cases), but the structure you describe, while technically feasible, would probably not be a good foundation. 在关系数据库中表示数据的“最佳”方式取决于您的特定用例(以及潜在的将来用例),但是您描述的结构虽然在技术上可行,但可能不是一个好的基础。 Also, I don't see how PROCEDURE is related (it's used for creating stored procedures which is a pretty advanced topic in itself). 另外,我看不到PROCEDURE是如何关联的(它用于创建存储过程 ,这本身就是一个相当高级的主题)。

I recommend that you read some general tutorial on SQL and on relational data modeling. 我建议您阅读一些有关SQL和关系数据建模的常规教程。

One structure I can suggest, without knowing a lot about your requirements, but that would be more in line with SQL best practices is: 我可以建议一个结构,而无需过多了解您的需求,但这将更符合SQL最佳实践:

TABLE: student
COLUMNS: id, name

TABLE: course
COLUMNS: id, name

TABLE: course_date
COLUMNS: id, course_id, date

TABLE: course_student
COLUMNS: id, course_id, student_id

You can then use SQL join queries to get whatever data you need from that structure. 然后,您可以使用SQL连接查询从该结构中获取所需的任何数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM