Home > database >  Mysql update trigger to insert another table and then delete this data
Mysql update trigger to insert another table and then delete this data

Time:09-25

Such as: mysql update trigger to insert another table and then delete this data
 
Drop the trigger if the exists trigger_tb_carparkinoutrecord_update;
CREATE the TRIGGER trigger_tb_carparkinoutrecord_update AFTER the UPDATE ON tb_carparkinoutrecord
FOR EACH ROW
The BEGIN
IF @ disable_trigger IS NULL THEN
IF new ProcessingType not in (' outstanding master record, 'untreated auxiliary records') THEN
INSERT INTO tb_carparkinoutrecord_history SELECT temp_tb_carparkinoutrecord. *,
(CASE WHEN (isnull (biggest arOwnerName) OR (biggest arOwnerName=' ')) THEN 'temporary car ELSE biggest arOwnerName END) AS CarOwnerName
Be sad roupName chtistina georgina rossetti.british poetess, (CASE WHEN (isnull () OR be sad roupName chtistina georgina rossetti.british poetess (=")) THEN be sad roupName chtistina georgina rossetti.british poetess 'ELSE END) AS GroupName,
(SELECT GetParentGroupName (biggest arGroupGuid) AS Expr1) AS FullGroupName
The FROM
(SELECT * FROM tb_carparkinoutrecord as a uid=new the where of al-qeada guid) as temp_tb_carparkinoutrecord
LEFT the JOIN tb_carinfo as on b ((temp_tb_carparkinoutrecord InCarNO=biggest arNo) AND (temp_tb_carparkinoutrecord. CarColor=biggest arColor))
LEFT the JOIN tb_cargroup as c on (biggest be sad uid chtistina georgina rossetti.british poetess arGroupGuid=);
IF ROW_COUNT () & gt; 0 THEN
The DELETE FROM tb_carparkinoutrecord WHERE guid=new. Guid;
END IF;
END IF;
The SET @ disable_trigger=NULL;
END IF;
END

Delete data error, error: Can 't update table tb_carparkinoutrecord' stored in the function/trigger because it is already 2 by the statement which invoked this stored function/trigger
Excuse me, this should be how to deal with, I put my delete statements tb_carparkinoutrecord_history table in the insert trigger also not line, online, etc.,,

CodePudding user response:

If you face just insert the trigger data insert/update, appear this problem, because can cause cycle call.
Can complete the demand of creating a separate process

CodePudding user response:

reference 1st floor wangjian0228 response:
if you face just insert the trigger data insert/update, appear this problem, because can cause cycle call.
Can be done creating a separate process demand

When I was in the update trigger, trigger the content is the update data into the other table, and then delete this data

CodePudding user response:

If add @ disable_trigger=1, no longer perform the trigger in the process of execution

CodePudding user response:

Msyql should not support, you delete trigger's watch is the trigger

CodePudding user response:

reference 4 floor ZJCXC - personal WeChat public namesake reply:
msyql should not support, you trigger the delete trigger's watch is the

A trigger can only be used on a table?

CodePudding user response:

You the demand is not very good ah,
I just test (MYSQL 5.7), set up @ disable_trigger=1, useless, isn't this parameter,
I want to CALL a stored procedure do delete, found at the same mistake,
May these operations in a trigger is a transaction,
  • Related