Docsity

Compiler Design and Computer Network and, Lecture notes of Engineering

Toggle sidebar
bg1
School of Computer Science
And Engineering
Digital Assessment II , Fall Semester 2023-24
Class Number: VL2023240100990
Name : Adarsh Kumar Priyadarshi
Reg No : 21BCE0974
Course Name : Database Systems Lab
Course Code : BCSE302P
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44
pf45
pf46
pf47
pf48
pf49
pf4a
pf4b
pf4c
pf4d
pf4e
pf4f
pf50
pf51
pf52
pf53
pf54
pf55
pf56
pf57
pf58
pf59
pf5a
pf5b
pf5c
pf5d
pf5e
pf5f
pf60
pf61
pf62
pf63
pf64

Partial preview of the text

Download Compiler Design and Computer Network and and more Lecture notes Engineering in PDF only on Docsity!

School of Computer Science

And Engineering

Digital Assessment II , Fall Semester 2023-

Class Number: VL

Name : Adarsh Kumar Priyadarshi

Reg No : 21BCE

Course Name : Database Systems Lab

Course Code : BCSE302P

Create Doctor ( Doctor Id, Name, department, experience) and Patient ( Patient Id, Name, Doc Id, Admitted date, discharge date, disease) Use SQL to answer the below queries. 1.Create tables according to the structure specified above. 2.Change the data type of experience field from number to varchar. 3.Include a field age in the table Patient table. 4.Add the following constraints. a. Make doctorid as primary key in doctor table b. Doctorid as foreign key in patient table. c. Patient name in patient table as not null.

  1. Insert the 5 records in each table such that the below queries gives at least one record as output.
  2. Display the patient id and name whose name starts with ā€˜A’ and ends with ā€˜N’. 7.Display the number of days the patient is admitted in the hospital.
  3. Display the doctor details along with their patient details.
  4. Doctors without any patient should also be listed in the output. 10.Display the patient name and patient_id who were admitted more than a month in the hospital and serviced by a doctor in ophthalmology department. 11.Retrieve the details of doctor who have more than 2 patients.

Output: -

2.Change the data type of experience field from number to varchar Code: - ALTER TABLE Doctor MODIFY Experience VARCHAR(50); Output: -

3.Include a field age in the table Patient table Code: - ALTER TABLE Patient ADD Age INT; Output: -

4.Add the following constraints. a. Make doctorid as primary key in doctor table b. Doctorid as foreign key in patient table. c. Patient name in patient table as not null. Code: - ALTER TABLE Doctor ADD CONSTRAINT PK_Doctor PRIMARY KEY (DoctorId); ALTER TABLE Patient ADD CONSTRAINT FK_Patient_Doctor FOREIGN KEY (DocId) REFERENCES Doctor(DoctorId); ALTER TABLE Patient MODIFY Name VARCHAR(100) NOT NULL;

  1. Insert the 5 records in each table such that the below queries gives at least one record as output. Code: - -- Insert records into the Doctor table INSERT INTO Doctor (DoctorId, Name, Department, Experience) VALUES (1, 'Dr. John Doe', 'Cardiology', '10 years'); INSERT INTO Doctor (DoctorId, Name, Department, Experience) VALUES (2, 'Dr. Jane Smith', 'Pediatrics', '5 years'); INSERT INTO Doctor (DoctorId, Name, Department, Experience) VALUES (3, 'Dr. Michael Johnson', 'Orthopedics', '8 years'); INSERT INTO Doctor (DoctorId, Name, Department, Experience) VALUES (4, 'Dr. Sarah Adams', 'Ophthalmology', '3 years'); INSERT INTO Doctor (DoctorId, Name, Department, Experience) VALUES (5, 'Dr. Emily Wilson', 'Dermatology', '6 years'); -- Insert records into the Patient table INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (1, 'Alice Nelson', 1, TO_DATE('2023-01-10', 'YYYY-MM-DD'), TO_DATE('2023-01-15', 'YYYY-MM-DD'), 'Fever'); INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (2, 'Benjamin Anderson', 1, TO_DATE('2023-02-05', 'YYYY-MM-DD'), TO_DATE('2023- 02-10', 'YYYY-MM-DD'), 'Cough'); INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (3, 'Amy Johnson', 1, TO_DATE('2023-03-20', 'YYYY-MM-DD'), TO_DATE('2023-03- 25', 'YYYY-MM-DD'), 'Headache'); INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (4, 'Andrew Martin', Null, TO_DATE('2023-04-15', 'YYYY-MM-DD'), TO_DATE('2023- 04-25', 'YYYY-MM-DD'), 'Fracture'); INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (5, 'Anna Jackson', 1, TO_DATE('2023-05-01', 'YYYY-MM-DD'), TO_DATE('2023-05- 30', 'YYYY-MM-DD'), 'Eye Infection'); INSERT INTO Patient (PatientId, Name, DocId, AdmittedDate, DischargeDate, Disease) VALUES (6, 'Adarsh', Null, TO_DATE('2023-05-01', 'YYYY-MM-DD'), TO_DATE('2023-05-30', 'YYYY-MM-DD'), 'Eye Infection');

Output: -

7.Display the number of days the patient is admitted in the hospital. Code: - SELECT PatientId, Name, AdmittedDate, DischargeDate, (DischargeDate

  • AdmittedDate) AS AdmittedDays FROM Patient;

Output: -

  1. Doctors without any patient should also be listed in the output. Code: - SELECT D.DoctorId, D.Name AS DoctorName, D.Department, P.PatientId, P.Name AS PatientName FROM Doctor D LEFT JOIN Patient P ON D.DoctorId = P.DocId; Output: -

10.Display the patient name and patient_id who were admitted more than a month in the hospital and serviced by a doctor in ophthalmology department. 11.Retrieve the details of doctor who have more than 2 patients. Code: - SELECT P.PatientId, P.Name AS PatientName FROM Patient P JOIN Doctor D ON P.DocId = D.DoctorId WHERE P.DischargeDate > ADD_MONTHS(P.AdmittedDate, 1) AND D.Department = 'Ophthalmology'; Code: - SELECT D.DoctorId, D.Name AS DoctorName, D.Department, COUNT(P.PatientId) AS PatientCount FROM Doctor D LEFT JOIN Patient P ON D.DoctorId = P.DocId GROUP BY D.DoctorId, D.Name, D.Department HAVING COUNT(P.PatientId) > 2;

School of Computer Science

And Engineering

Digital Assessment, Fall Semester 2023-

Class Number: VL

Name : Adarsh Kumar Priyadarshi

Reg No : 21BCE

Course Name : Database Systems Lab

Course Code : BCSE302P