[Database design] mysql+jsp realizes housing rental management system (system design related code)

System design related code

1. Stored procedure code

(1) Stored procedures that change the state of the house

DELIMITER $$
CREATE 
	PROCEDURE changeCon(IN _HID INT,IN flag INT)
	BEGIN
		IF (flag = 1) THEN 
			UPDATE House
			SET con = 1
			WHERE House.HID = _HID;
        ELSE 
			UPDATE House
			SET con = 0
			WHERE House.HID = _HID;
        END IF;
	END$$
DELIMITER ;

(2) Query the stored procedure of the house number corresponding to the corresponding charge record

DELIMITER $$
CREATE 
	PROCEDURE findHID(IN _CID INT,OUT _HID INT)
	BEGIN
		SELECT 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 $$
CREATE TRIGGER tri1 AFTER INSERT ON Charge FOR EACH ROW
BEGIN
	CALL 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 $$
CREATE TRIGGER tri2 BEFORE DELETE ON Charge FOR EACH ROW
BEGIN
	CALL findHID(OLD.CID,@HID2);
    CALL changeCon(@HID2,0);
END$$
DELIMITER ;

Guess you like

Origin blog.csdn.net/qq_51152918/article/details/126729979