我想设置一个触发器,以便在更新时'SyncStatus'= 1,然后触发器将更新'SyncStatusTimestamp'= Current_Time_Stamp。
但是我在说错误:
错误:
无法在存储的函数/触发器中更新表'bloodpressurebattery' 因为它已被调用此存储的语句使用 功能/触发
-----------表格详情-------------
CREATE TABLE `bloodpressurebattery` (
`BloodPressureBatteryID` INT(11) NOT NULL AUTO_INCREMENT,
`ByDevSessionId` INT(11) NOT NULL,
`ByPatientId` INT(11) NULL DEFAULT NULL,
`ByDeviceId` INT(11) NULL DEFAULT NULL,
`Value` FLOAT NULL DEFAULT NULL,
`SequenceId` INT(11) NULL DEFAULT NULL,
`SyncStatus` INT(11) NULL DEFAULT '0',
`Timestamp` TIMESTAMP(3) NULL DEFAULT NULL,
`WrittenToAndroidDatabaseTimestamp` TIMESTAMP(3) NULL DEFAULT NULL,
`WrittenToServerDatabaseTimestamp6` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`SyncStatusTimestamp` TIMESTAMP(3) NULL DEFAULT '1970-01-01 00:00:01.000',
PRIMARY KEY (`BloodPressureBatteryID`),
INDEX `ByDevSessionId` (`ByDevSessionId`),
CONSTRAINT `bloodpressurebattery_ibfk_1` FOREIGN KEY (`ByDevSessionId`) REFERENCES `devicesession` (`DeviceSessionID`) ON UPDATE CASCADE
)
COLLATE='utf8_general_ci'
ENGINE=InnoDB
AUTO_INCREMENT=524874
;
----触发细节----------------------
DELIMITER //
CREATE TRIGGER SyncStatusTimestamp_bloodpressurebattery_after_update
AFTER UPDATE
ON bloodpressurebattery FOR EACH ROW
BEGIN
DECLARE _SyncStatusTimestamp INT ;
DECLARE _BloodPressureBatteryID INT ;
SET _BloodPressureBatteryID = (SELECT bloodpressurebattery.BloodPressureBatteryID As _BloodPressureBatteryID
FROM bloodpressurebattery
WHERE BloodPressureBatteryID = new.BloodPressureBatteryID AND SyncStatus = 1);
IF _BloodPressureBatteryID > 0 THEN
UPDATE bloodpressurebattery SET SyncStatusTimestamp = CURRENT_TIMESTAMP AND bloodpressurebattery.BloodPressureBatteryID = _BloodPressureBatteryID ;
END IF ;
END
答案 0 :(得分:0)
您收到该错误导致MySQL不支持递归触发器。您在bloodpressurebattery
表和UPDATE
上定义了一个装配工,您再次尝试通过以下DML语句访问同一个表
UPDATE bloodpressurebattery SET SyncStatusTimestamp = CURRENT_TIMESTAMP .....
存储函数不能递归使用。
•在存储的函数或触发器中,不允许修改a 已经被使用(用于读或写)的表 调用函数或触发器的语句。