DBMS Exp7
DBMS Exp7
22BCE10781
REG.NO :_________________________
NAME :_________________________
Garv Goyal
BTech CSE
BRANCH :_________________________
Fall Semester 2024-25
SEMESTER:_________________________
Raise an exception if prescription and treatment received from
EXP.NO: 07
same doctor
Query
Assuming a patient
should not receive both treatment and prescription from the same doctor, write
a program to find out all the doctor who provide both treatment and
prescription to the same patient. In addition, raise and display an exception
if this situation occurs.
Table Creation
Create the doctors table:
CREATE TABLE doctors (
doctor_id INT PRIMARY KEY,
doctor_name VARCHAR(100)
);
doctors Table:
Doctor_id Doctor_name
1 Dr. Smith
2 Dr. Johnson
Patients Table:
Patient_id Patient_name
1 John Doe
2 Jane Doe
Create the treatments table:
CREATE TABLE treatments (
treatment_id INT PRIMARY KEY,
patient_id INT,
doctor_id INT,
treatment_date DATE,
FOREIGN KEY (patient_id) REFERENCES patients(patient_id),
FOREIGN KEY (doctor_id) REFERENCES doctors(doctor_id)
);
Treatments table:
Prescriptions table:
SELECT t.doctor_id
INTO doctor_id
FROM treatments t
WHERE t.patient_id = NEW.patient_id AND t.doctor_id = NEW.doctor_id;