Picture 8.1
8 of 8
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,we can see that the DepartmentID of the doctor with DepartmentID=null is set to the id of the department named 'Cardiology' as shown in the following figure:
insert into Doctors (DoctorID, FirstName, LastName, PhoneNumber, Email, DepartmentID)values (70,'Van Chien', 'Nguyen', '0928367812', '
[email protected]', null),(71,'Thi Binh', 'Nguyen', '0989278127', '
[email protected]',5)
select * from Doctors where DoctorID in (70,71)
DoctorID FirstName LastName Phone Number Email 70 71 DepartmentID Van Chien Nguyen 0928367812
[email protected] 1 Thi Binh Nguyen 0989278127
[email protected] 5 1 2
Picture 9.1
Paper No: 6
Question 10:
Write statements to delete from the Tests table two tests named 'Blood Test' and 'CT Scan'and to delete also from the AppointmentTests table all rows corresponding to those two tests.
Close