简体   繁体   English

如何构建MySQL每日检查表数据库

[英]How to structure MySQL daily checklist database

I am trying to create a database application for daily task.我正在尝试为日常任务创建一个数据库应用程序。 I am converting a paper form I use.我正在转换我使用的纸质表格。

Each row is a task and each column is a date.每行是一个任务,每列是一个日期。 Every day I go through and complete the task and initial the cell that corresponds with the date.每天我 go 通过并完成任务并在与日期对应的单元格上签名。 But not every task is required daily.但并非每天都需要完成每项任务。 I included an example of how it will appear in the browser.我提供了一个示例,说明它将如何显示在浏览器中。

How do I structure the database?我如何构建数据库?

在此处输入图像描述

You could do:你可以这样做:

TasksDefinition
    Id         PK
    TaskName   NN

TasksWhen
    Id         PK
    TaskId     FK, TasksDefinition.id
    Day        NN  --> what day should task Id be completed

History
    Id         PK
    TaskId     FK, TasksDefinition.Id
    Date       NN
    Done       NN, boolean, default False
  • PK: primary key PK:主键

  • FK: foreign key FK:外键

  • NN: not null NN:不是 null

  • Each task is defined in TasksDefinition每个任务都在 TasksDefinition 中定义

  • TasksWhen stores the information on what day(s) should each task be completed. TasksWhen 存储每项任务应该在哪一天完成的信息。 One entry per task/day of the month (ex. 1 to 31).每个月的每个任务/天一个条目(例如 1 到 31)。 OR 0-6 if you want to use week days.或者 0-6,如果你想使用工作日。 Using a table allows you to have some tasks completed on many days.使用表格可以让您在许多天内完成一些任务。 Ex.前任。 for task X, on day 1, 4, and 28 would require 3 entries in TasksWhen.对于任务 X,在第 1、4 和 28 天需要 TasksWhen 中的 3 个条目。

At 0001 each day, your application does:在每天 0001,您的应用程序执行以下操作:

  • Add each tasks that have to be completed that day to the History table, with the current date and Done == False.将当天必须完成的每个任务添加到历史表中,并使用当前日期和 Done == False。
  • When you have completed the task, change History.Done to True.完成任务后,将 History.Done 更改为 True。

When you build your interface, you query the history table only.当你构建你的界面时,你只查询历史表。 This will give you which tasks have been done (or not) on each day.这将为您提供每天完成(或未完成)的任务。 The status of completion goes to the History table as well.完成状态也会进入历史表。

You can use day of month or week day to specify which tasks must be done on each day.您可以使用月中的某天或工作日来指定每天必须完成哪些任务。 You could even use a mix of both.您甚至可以混合使用两者。 As long as your application can figure it out, you would be fine.只要您的应用程序能够弄清楚,您就可以了。

The monthly report is built from data in the history table.月度报告是根据历史表中的数据构建的。

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

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