it seems simple, but still a challenge. I simplified my issue as much as possible.
I have this test_table with one record:
id | cost_per_record
1 | 24
After an INSERT I want the table to look like this:
id | cost_per_record
1 | 12
2 | 12
From the application I work from I cannot CALL a STORED PROCEDURE so the code I used among others:
DROP TABLE IF EXISTS `test_table`;
CREATE TABLE `test_table` (
`id` int(11) NOT NULL,
`cost_per_record` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
INSERT INTO `test_table` (`id`, `cost_per_record`) VALUES (1,24);
DELIMITER $$
CREATE TRIGGER `test_insert` BEFORE INSERT ON `test_table` FOR EACH ROW
BEGIN
update `test_table` set `cost_per_record` = 12
where `id` = 1;
END
$$
DELIMITER ;
INSERT INTO `test_table` (`id`, `cost_per_record`) VALUES
(2,12);
The error I usually receive (also on other attempts):
MySQL said: Documentation
#1442 - Can't update table 'kan_test_update' in stored function/trigger because it is already used by statement which invoked this stored function/trigger
Believe me, I read quite some answers on this forum and also ran into blogs saying this is impossible. But I am (still) not accepting this. So.. any solution... thanks...