Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Question What integration level should an employer choose?

Answered: 1 week ago