Database table design for scheduling tasks

后端 未结 5 1322
悲哀的现实
悲哀的现实 2020-12-08 05:09

I want to be able to create schedules that can be executed based on a fixed date, repeated daily, repeated on a particular day of the week, repeated on a particular month of

5条回答
  •  星月不相逢
    2020-12-08 06:02

    I think the accepted answer is much more complicated than it needs to be. This can be done with a single table like this:

    Schedules
    
     - Id :int
     - Greetingid :int
     - Startdate :date
     - Frequencytype :char(1)
     - Frequencyinterval :int
     - Timeofday :time
    

    Frequencytype would be one of the following values

    • 'O' = Once
    • 'D' = Daily
    • 'W' = Weekly
    • 'M' = Monthly
    • 'A' = Annually

    Frequencyinterval would be numeric and the meaning of the value depends on the value of frequencytype

    • If type = 'Once' then value = 0 (no interval) schedule would execute on startdate
    • If type = 'Daily' then value = # of days interval
    • If type = 'Weekly' then 1 through 7 for day of the week
    • If type = 'Monthly' then 1 through 31 for day of the month
    • If type = 'Annually' then 1 through 365 for day of the year

提交回复
热议问题