How can I make a constraint so that the appointment cannot be repeated?

79
November 29, 2021, at 02:20 AM

I want to make a constraint so that the appointment with a certain doctor cannot be repeated more than once. For example, if a person chooses an appointment on 11/09/2021 from 15:00 until 15:30, the same appointment cannot be booked again at the same doctor. phpMyAdmin virgin is: Server version: 10.4.10-MariaDB

CREATE OR REPLACE TABLE appointments (
    AppId     int(11) PRIMARY,
    docID     int(11),
    patientID int(11),
    AppStart  datetime,
    AppEnd    datetime
  )
Answer 1

You can do:

alter table appointments
add constraint unique_dr_app_start unique (docID, AppStart);

Example:

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

Duplicate entry '123-2021-11-25 12:30:00' for key 'unique_dr_app_start'

EDIT -- Include end appointment validation

You can additionally set up the constraint:

alter table appointments
add constraint unique_dr_app_end unique (docID, AppEnd);

You can see it at work by trying:

insert into appointments (AppId, docID, AppStart) 
values (4, 123, '2021-11-25 10:30:00'); -- error

Duplicate entry '123-2021-11-25 10:30:00' for key 'unique_dr_app_start'

READ ALSO
How can I add individual html links into folium's popup window

How can I add individual html links into folium's popup window

I want to add individual html links of google search to the popups on a folium map according to the name of the street the icon is placed

39
Conditional link styling React

Conditional link styling React

I want my nav bar to style the page title I'm in, im using React and Tailwind CSS, for example, just make the title yellow when im on the selected path

51
How to mock async method with axios.post using sinon?

How to mock async method with axios.post using sinon?

I am trying to mock an async function which internally calls n async method in another js fileWhen i mock the the async function, it says 'expected post to be caaled atleast once'

46
Cannot read properties of undefined (reading 'length') in recursive view

Cannot read properties of undefined (reading 'length') in recursive view

I am trying to simply check if I have an empty array but I get this error when I run this:

62