(1) Stored procedures that change the state of the house
DELIMITER $$
CREATEPROCEDURE changeCon(IN _HID INT,IN flag INT)BEGINIF(flag =1)THENUPDATE House
SET con =1WHERE House.HID = _HID;ELSEUPDATE House
SET con =0WHERE House.HID = _HID;ENDIF;END$$
DELIMITER;
(2) Query the stored procedure of the house number corresponding to the corresponding charge record
DELIMITER $$
CREATEPROCEDURE findHID(IN _CID INT,OUT _HID INT)BEGINSELECT HID
INTO _HID
FROM Charge,Record
WHERE Charge.RID = Record.RID;END$$
DELIMITER;
2. Trigger code
(1) The status trigger of the rented house (when the renter successfully rents the house, the status of the rented house is updated to 1, indicating that the house has been rented)
DELIMITER $$
CREATETRIGGER tri1 AFTERINSERTON Charge FOR EACH ROWBEGINCALL findHID(NEW.CID,@HID1);CALL changeCon(@HID1,1);END$$
DELIMITER;
(2) Check-out house status trigger (when the renter checks out successfully, update the status of the returned house to 0, indicating that the house is not rented)
DELIMITER $$
CREATETRIGGER tri2 BEFORE DELETEON Charge FOR EACH ROWBEGINCALL findHID(OLD.CID,@HID2);CALL changeCon(@HID2,0);END$$
DELIMITER;