我的触发器有问题。
DELIMITER $$
CREATE TRIGGER complete_transation
AFTER INSERT ON transaction
FOR EACH ROW BEGIN
DECLARE id_trans INT;
DECLARE id_stock INT;
DECLARE type_transaction BIT(1);
DECLARE id_match INT;
SET @id_trans = NEW.idTransaction;
SET @id_stock = NEW.stock_idStocks;
SET @type_transaction = NEW.type;
IF(@type_transaction = 1) THEN
SET @id_match = (SELECT idTransaction FROM transaction WHERE stock_idStocks = @id_stock AND type = 0);
UPDATE transaction SET status = 1 WHERE idTransaction = @id_match;
END IF;
IF(@type_transaction = 0) THEN
SET @id_match = (SELECT idTransaction FROM transaction WHERE stock_idStocks = @id_stock AND type = 1);
UPDATE transaction SET status = 1 WHERE idTransaction = @id_match;
END IF;
END$$
DELIMITER ;
是否有机会更改调用触发器的表中的其他记录?
答案 0 :(得分:0)
在存储的函数或触发器中,不允许通过调用函数或触发器的语句修改已经使用(用于读取或写入)的表。 触发器触发时可能会锁定表格。