Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write SQL statements to answer questions 1.1, 1.2, 1.3 and 1.4 based on the following schema. Primary keys are (BOLD and italicized) and attributes with

Write SQL statements to answer questions 1.1, 1.2, 1.3 and 1.4 based on the following schema. Primary keys are (BOLD and italicized) and attributes with the same names in different tables are foreign keys.

Doctors(doctorId INT, doctorName VARCHAR, specialty)

Patients(patientId, patientName, sex, patientBalance, numberOfVisits)

Records(doctorId, patientId, date, diagnosis, visitCost)

1.1) Create a view, called DoctorSmithsPatients, to list all the patients Dr. Smith has.

1.2) Write a trigger, each time a row is inserted in the table Records, the numberOfVisits in the corresponding Patient row is updated by 1 (i.e. add 1 to the numberOfVisits). Hint: Consider using Update statement.

1.3) Find the cost of the most expensive visit (Remember: Aggregate functions)

1.4) For each doctor, list doctor identifier, doctor name and the total number of visits that were administered by the doctor. (Remember: Aggregate/GROUP BY)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Synthesis Bridging Computer Science And Information Technology

Authors: Barry Dwyer

1st Edition

0128054492, 9780128054499

More Books

Students also viewed these Databases questions