If your DBMS supports the ANSI "CREATE ASSERTION" syntax then you could use that. It would be
something like:
Code:
CREATE ASSERTION x CHECK
NOT EXISTS
( SELECT NULL FROM appointments a, appointments b
WHERE a.patient_id = b.patient_id
AND a.start <= b.end
AND b.start <= a.end
);
However, Oracle for one DBMS does
not support assertions, and you would have to use other methods e.g. triggers or materialized views with constraints.