1

Topic: The trigger does not work

Under the job it is necessary to create the trigger which at performance of function INSERT for table 1 would interpose into table 2 an amount of lines in table 1.
The trigger:
create trigger up_insert
before insert
on task24
for each row
update task24u
set co2 = count (task24.c1) where co1 = 2
After that I execute a command:
INSERT INTO ` task24 ` (` co1 `, ` co2 `, ` co3 `) VALUES (NULL, ' kk ', ' kkk ');
But the error takes off:
1:55:32 PM INSERT INTO ` task24 ` (` co1 `, ` co2 `, ` co3 `) VALUES (NULL, ' kk ', ' kkk ') Error Code: 1111. Invalid use of group function 0.000 sec
Tried before and after

2

Re: The trigger does not work

bruce159357 wrote:

it is necessary to create the trigger which at performance of function INSERT for table 1 would interpose into table 2 an amount of lines in table 1

But your trigger does not interpose (an insertion === INSERT) anything into the second table, and only updates (UPDATE) there the data.
The error report is clear, I think. , easier the first step it is necessary to receive a record count in a variable
SELECT COUNT (1) INTO @num;
And the second step already to use a variable in update of records of the second table.

bruce159357 wrote:

Tried before and after

the Difference should be only in + / - 1 records smile

3

Re: The trigger does not work

CREATE TRIGGER up_insert
BEFORE INSERT ON task24
FOR EACH ROW
INSERT INTO task24u (co2)
SELECT COUNT (*) FROM task24;

4

Re: The trigger does not work

vkle;
If fairly not especially I understand with databases can help to write?

5

Re: The trigger does not work

bruce159357;
Thanks all for the help. The trigger already works)
Can still with 1 help?
The trigger which before function performance update will be necessary to transfer changeable values to other table.

6

Re: The trigger does not work

Akina;
Thanks for the help. The trigger already works)
Can still with 1 help?
The trigger which before function performance update will be necessary to transfer changeable values to other table.

7

Re: The trigger does not work

The example of the working trigger - is. Logic - the elementary to a triviality. Give independently.