SQL statements for Tables: Patient, Doctor and Appointment II

Consider the following relational database:

  • Patient(PID, Pname, Paddress, Pgender, disease)
  • Doctor(DID, Dname, Daddress, Department, salary)
  • Appointment(PID, DID, time)

 

Write SQL statements for the following:

  1. Insert a new tuple in the relation patient.
  2. List all the patients who were checked by doctors Pankaj and Rubi.
  3. List name and id of doctors whose salary is less than Rs. 120,000.
  4. Find name of patients whose name begins with 'Ru'.
  5. Increase salary of all doctors by 10% who works in Forensic department.


a. Insert a new tuple in the relation patient.


INSERT INTO Patient
VALUES      ('P008',
             'Ramesh',
             'Dhangadhi',
             'Male',
             'Fever'); 


b. List all the patients who were checked by doctors Pankaj and Rubi.


SELECT p.PID,
       p.Pname
FROM   Patient p
       JOIN Appointment a
         ON p.PID = a.PID
       JOIN Doctor d
         ON d.DID = a.DID
WHERE  d.Dname = 'Pankaj'
        OR d.Dname = 'Rubi'; 


c. List name and id of doctors whose salary is less than Rs. 120,000.


SELECT Dname,
       DID
FROM   Doctor
WHERE  salary < 120000; 


d. Find name of patients whose name begins with 'Ru'.


SELECT Pname
FROM   Patient
WHERE  Pname LIKE 'Ru%'; 


e. Increase salary of all doctors by 10% who works in Forensic department.


UPDATE Doctor
SET    salary = salary * 1.10
WHERE  department = 'Forensic'; 

 

Asked in Year
2022
Course
BBM
University
TU