我正在将触发器创建到Mysql Workbanch中,但是无法创建触发器。 有人可以帮我吗?
DELIMITER $$
create TRIGGER Insert_Test
After Delete ON Test
FOR EACH ROW
BEGIN
START TRANSACTION;
DECLARE v_ID INT;
DECLARE v_Error TINYINT;
DECLARE v_AgentID INT;
SELECT v_Error = 0;
v_ID=Old.id;
BEGIN
DELETE Test2 WHERE id = SELECT id FROM Test where id=v_ID;
Rollback;
SET v_Error = 1;
END
IF v_Error = 0;
THEN
COMMIT;
ELSEIF
v_Error = 1;
THEN
ROLLBACK;
END IF;
END
DELIMITER ;
Sql服务器触发器
ALTER TRIGGER [dbo].[tr_DelRecordTypeID] ON [dbo].[luRecordType] FOR DELETE
AS
SET NOCOUNT ON
BEGIN TRANSACTION
DECLARE @ID INT, @GroupTypeID INT, @Error BIT, @Msg VARCHAR(500)
SELECT @Error = 0
SELECT @ID = RecordTypeID FROM deleted
SELECT @GroupTypeID = 30
IF EXISTS ( SELECT g.GroupID
FROM luGroup g,
[luGroupDetail] gd
WHERE g.[GroupID] = gd.[GroupID]
AND g.[GroupTypeID] = @GroupTypeID
AND gd.[MemberID] = @ID )
BEGIN
DELETE [agAgent] WHERE [AgentID] = (SELECT TOP 1 AgentID FROM agAgentPayType)
Rollback transaction
SET @Error = 1
END
IF @Error = 0
BEGIN
COMMIT TRANSACTION
END
ELSE
IF @Error = 1
BEGIN
ROLLBACK TRANSACTION
END
我正在尝试实现此触发器到mysql workbanch,请检查
我会感激的
谢谢
阿曼