c# - 在数据库中表示 "Recurring Events"的最佳方式是什么?

标签 c# sql database-design data-modeling

我正在尝试使用 C# 开发一个依赖于调度程序和日历的事件应用程序,其中一个关键要求是在数据库中表示重复发生的事件。 在数据库中表示重复事件的最佳方式是什么?

更多详情:

在创建事件时,我还会向某些用户发送邀请,并且应允许被邀请者仅在指定窗口( session 持续时间)内登录 session ,或者当被邀请者尝试登录时可能会拒绝登录说,预定 session 开始前 5 分钟。

最佳答案

sysjobs , sysjobsschedulesysschedules SQL Server 中的表在这方面做得很好。我不会重新发明轮子,我只会复制他们的设计。

以下是 sysschedules

中的一些重要字段

频率类型

How frequently a job runs for this schedule.

1 = One time only

4 = Daily

8 = Weekly

16 = Monthly

32 = Monthly, relative to freq_interval

64 = Runs when the SQL Server Agent service starts

128 = Runs when the computer is idle

频率间隔

Days that the job is executed. Depends on the value of freq_type. The default value is 0, which indicates that freq_interval is unused. Value of freq_type Effect on freq_interval

1 (once) freq_interval is unused (0)

4 (daily) Every freq_interval days

8 (weekly) freq_interval is one or more of the following: 1 = Sunday 2 = Monday 4 = Tuesday 8 = Wednesday 16 = Thursday 32 = Friday 64 = Saturday

16 (monthly) On the freq_interval day of the month

32 (monthly, relative) freq_interval is one of the following: 1 = Sunday 2 = Monday 3 = Tuesday 4 = Wednesday 5 = Thursday 6 = Friday 7 = Saturday 8 = Day 9 = Weekday 10 = Weekend day

64 (starts when SQL Server Agent service starts) freq_interval is unused (0)

128 (runs when computer is idle) freq_interval is unused (0)

freq_subday_type

Units for the freq_subday_interval. Can be one of the following values: Value Description (unit)

1 At the specified time

2 Seconds

4 Minutes

8 Hours

freq_subday_interval

Number of freq_subday_type periods to occur between each execution of the job.

频率相对间隔

When freq_interval occurs in each month, if freq_interval is 32 (monthly relative). Can be one of the following values:

0 = freq_relative_interval is unused

1 = First

2 = Second

4 = Third

8 = Fourth

16 = Last

freq_recurrence_factor

Number of weeks or months between the scheduled execution of a job. freq_recurrence_factor is used only if freq_type is 8, 16, or 32. If this column contains 0, freq_recurrence_factor is unused.

关于c# - 在数据库中表示 "Recurring Events"的最佳方式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1579638/

相关文章:

c# - 如何使我创建的类或 DLL 出现在 VS 工具箱中

c# - 参数化查询(C#、Oracle): How to produce a more readable representation?

sql - PostgreSQL 中的外键匹配

mysql - 我应该将 EAV 值放入数据类型表中吗?

c# - 不在接口(interface)中的类方法

c# - 如何生成指向不在 WebAPI 路由表中的资源的链接?

c# - 事件未在表单中正确引发

SQL查询从双重返回N行

php - MySQL将两个表中的两个字段合并为结果集中的一个字段

asp.net-mvc - 将 1 个数据库用于帐户信息和内容是否正确