For example, when we call the F1 function in the following query for calculating the number of distinct patients having appointments with the two departments 'Cardiology' and 'Pediatrics', the results must be shown as in the following figure:
select DepartmentID, Name, dbo. F1 (DepartmentID) as NumberOfPatients
from Departments
where Departments.Name in ('Cardiology', 'Pediatrics')
DepartmentID
1
3
Name
NumberOfPatients
Cardiology 37
Pediatrics
32
1
2
Picture 8.1
Question 9:
Create a trigger named insertDoctor for the INSERT statement on the "Doctors" table so that when we execute an insert statement to add one or more rows to the "Doctors" table, if any of the inserted rows have the DepartmentID as null, the system will automatically set the DepartmentID of those rows to the DepartmentID of the department named 'Cardiology'.
For example, if we execute the following statements to insert two doctors (one with DepartmentID=NULL and the other with DepartmentID=5) and then select these two doctors,
Close
+ 100%
Zoom