반응형
어떻게 하면 약속이 반복되지 않도록 제한할 수 있습니까?
특정 의사와의 예약이 두 번 이상 반복되지 않도록 제한하고 싶습니다.예를 들어, 2021년 11월 9일 15:00부터 15:30까지 예약을 선택한 경우 동일한 예약을 동일한 의사에게 다시 예약할 수 없습니다.phpMyAdmin버진: 서버 버전: 10.4.10-마리아DB
CREATE OR REPLACE TABLE appointments (
AppId int(11) PRIMARY,
docID int(11),
patientID int(11),
AppStart datetime,
AppEnd datetime
)
할 수 있는 일:
alter table appointments
add constraint unique_dr_app_start unique (docID, AppStart);
예:
insert into appointments (AppId, docID, AppStart)
values (1, 123, '2021-11-25 12:30:00'); -- OK
insert into appointments (AppId, docID, AppStart)
values (2, 123, '2021-11-25 10:30:00'); -- OK
insert into appointments (AppId, docID, AppStart)
values (3, 123, '2021-11-25 12:30:00'); -- error
키 'unique_dr_app_start'에 대한 중복 항목 '123-2021-11-25 12:30:00'
편집 - 종료 약속 유효성 검사 포함
제약 조건을 추가로 설정할 수 있습니다.
alter table appointments
add constraint unique_dr_app_end unique (docID, AppEnd);
작업 중에 다음을 시도하면 확인할 수 있습니다.
insert into appointments (AppId, docID, AppStart)
values (4, 123, '2021-11-25 10:30:00'); -- error
키 'unique_dr_app_start'에 대한 중복 항목 '123-2021-11-25 10:30:00'이(가) 있습니다.
언급URL : https://stackoverflow.com/questions/70118492/how-can-i-make-a-constraint-so-that-the-appointment-cannot-be-repeated
반응형
'programing' 카테고리의 다른 글
Reactjs, Typescript - 속성이 하위 구성 요소에 없습니다. (0) | 2023.06.12 |
---|---|
SHA-1을 안드로이드 애플리케이션에 추가하는 방법 (0) | 2023.06.12 |
MariaDB: 사례를 사용하여 수행된 작업과 요청 일치(합계 > 0) (0) | 2023.06.12 |
키 누르기를 감지하는 방법은 무엇입니까? (0) | 2023.06.12 |
git pull이 "참조 확인 실패" "로컬 참조 업데이트 실패" (0) | 2023.06.12 |