dtt3399 2013-11-07 18:13
浏览 35

MySQL触发失败的更新调用插入

I would like to have a Trigger on a failed Update which will insert into the same table.

If possible, I would prefer avoiding any additional php and SELECT due to performance.

So I thought of something like this for the TRIGGER:

CREATE TRIGGER `onChunksUpdate` AFTER UPDATE ON  `chunks` 
FOR EACH ROW 

IF ROW_COUNT() = 0 
THEN INSERT INTO chunks( scopeX, scopeY, targets ) 
VALUES (NEW.scopeX, NEW.scopeY, NEW.targets);
END IF ;

And the executed Update statement(php):

UPDATE chunks SET targets = CONCAT(targets, ',{$id}') WHERE scopeX={$chunkX} AND scopeY={$chunkY}

Furthermore I am not sure, wether a failed update call would still execute a TRIGGER of the time AFTER.

Thanks for any help, I googled very much to find any help but I found nothing.

  • 写回答

0条回答 默认 最新

    报告相同问题?