简体   繁体   中英

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. 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

  • FK: foreign key

  • NN: not null

  • Each task is defined in TasksDefinition

  • TasksWhen stores the information on what day(s) should each task be completed. One entry per task/day of the month (ex. 1 to 31). OR 0-6 if you want to use week days. 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.

At 0001 each day, your application does:

  • Add each tasks that have to be completed that day to the History table, with the current date and Done == False.
  • When you have completed the task, change History.Done to 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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