Question
I have the following 2 tables: table1 and table2 as described below: +-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra
I have the following 2 tables: table1 and table2 as described below:
+-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | var | int(5) | YES | | NULL | | +-------+--------+------+-----+---------+----------------+
table2:
> desc table2; +-------+--------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-------+--------+------+-----+---------+----------------+ | id | int(5) | NO | PRI | NULL | auto_increment | | var1 | int(5) | YES | | NULL | | | var2 | int(5) | YES | | NULL | | +-------+--------+------+-----+---------+----------------+
i created a trigger so table2.var2 is calculated using table1.var * table2.var1:
create trigger tot after insert on table2 for each row update table2 set var2 = table1.var * table2.var2;
When I insert into table2 i get an error:
MariaDB [test_db]> insert into table2 (var1)values('5'); ERROR 1442 (HY000): Can't update table 'table2' in stored function/trigger because it is already used by statement which invoked this stored function/trigger.
Is there a way to do it?
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started