考勤数据库的良好数据库设计(架构)是什么?

2021-12-26 00:00:00 mysql database-design

我正在尝试申请一个亲戚的武术工作室的出勤率.我试过四处寻找一些类似的例子,但我找不到适合这种应用程序的任何具体或足够清晰的例子.

I'm trying to make a application for keeping attendance for a relative's martial arts studio. I've tried looking around for some similar examples, but I couldn't find any specific or clear enough ones for this kind of application.

目前,我使用了两个表,一个用于保存学生信息,students(id, first_name, last_name, email, ...),另一个表用于按一年中的周数出勤,出席(id,周_1、周_2、周_3、...).我试图改变它以保持几天的出勤率,但似乎想不出一个好的方法,因为我对 MySQL 还是有点陌生​​.

At the moment, I am using two tables, one for keeping student information, students(id, first_name, last_name, email, ...), and another table for attendance by the weeks in a year, attendance(id, week_1, week_2, week_3, ...). I am trying to change it to keep attendance by days instead, but can't seem to think of a good approach since I'm still kind of new to MySQL.

我正在努力使其能够以类似日历的格式查看出席情况.只制作 365 天的列可能会很糟糕……每个月都有一张表格也是如此.我注意到一些类似的应用程序只是跟踪日期,并将其存储在数据库中.这种方法会更好吗?或者,是否有其他更好的方法来设计这种数据库?提前致谢.

I am trying to make it so it is possible to see the attendance in a calendar-like format. It probably would be bad to just make columns for 365 days... and same with having a table for each month. I've noticed some similar applications just keep track of the dates, and store that in the database. Would this approach be better? Or, is there some other better approach to designing this kind of database? Thanks in advance.

推荐答案

出勤应该有 id、student_id 和 date.这是您在学生参加时需要记录的全部内容.如果您想知道在特定日期有多少学生(以及谁)就读,您可以针对该特定日期或日期范围运行查询.

Attendance should have id, student_id and date. This is all you need to record when students attended. if you want to know how many students attended on a specific date (and who) you run a query for that specific date or date range.

您还可以创建一个课程表,在这种情况下,出勤表将是id、student_id 和 course_id课桌可以是id,hold_on_date

You could also create a lesson table, in which case the attendance table would be id, student_id and lesson_id the lesson table could be id, held_on_date

除非您需要在课程表中添加更多列,否则我认为这是矫枉过正.

unless you need to add more columns to the lesson table, I think it is overkill.

相关文章