間隔をテーブルに保存するとします。間隔は、単一の日付または範囲として指定できるため、フィールドは次のようになります。
| id | since | until | at_date |
今、私はsince is null and until is not null
orのような状況since is not null and until is null
が起こらないことを望みますが、 と の両方since is null and until is null
でsince is not null and until is not null
問題ありません (最初の 1 つは、 が指定されている場合にのみ問題ありat_date
ません)。
おそらく、「マージ」until
しsince
て 1 つの列にすることは理にかなっていますが、私の状況では、どちらか一方のみを選択することが理にかなっている場合があるため、それらを別々に使用しても問題ないと思います。
編集:
create table menu_availability
(menu_id int not null,
daily_serving_start time null,
daily_serving_end time null,
weekly_service_off tinyint null,
one_time_service_off date null,
constraint ch_valid_week_day
check ((weekly_service_off is null)
or (weekly_service_off <= 6 and weekly_service_off >= 0)),
constraint ch_non_empty_schedule
check ((daily_serving_start is not null and daily_serving_end is not null)
or (daily_serving_start is null and daily_serving_end is null)),
constraint ch_either_week_or_time_set
check (daily_serving_start is not null
or weekly_service_off is not null
or one_time_service_off is not null),
constraint ch_only_week_or_one_time
check ((weekly_service_off is null and one_time_service_off is not null)
or (weekly_service_off is not null and one_time_service_off is null)))
これは私がこれまでに持っているものです...しかし、それは本当に面倒です...