Solved

Problem with trigger

Posted on 2011-02-17
1
833 Views
Last Modified: 2012-08-14
I am using mysql 5.1

I have two tables that I am working with. I have a product table and a discount table.

When a product gets added, I use an after insert trigger to create a record in the discount table. Here is the trigger. I am using navicat to create the trigger and this is how it displays. It is firing After>Insert

insert into discount (product_id,amount,is_percent) values (New.product_id,New.product_price-New.discount_price,0);

This trigger works great. What I have to do after this is update the product table with a value from the newly added record in the discount table. Here is that trigger. This fires After>Insert and is where I receive an error. This trigger is in my discount table.

update product SET product_discount_id = NEW.discount_id where product_id = NEW.product_id

Should this work?


0
Comment
Question by:J C
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 60

Accepted Solution

by:
Kevin Cross earned 500 total points
ID: 34922629
Firstly, remove ambiguity on the product_id column, then please post the error message you are getting.

i.e., use this code:
UPDATE product 
SET product.product_discount_id = NEW.discount_id
WHERE product.product_id = NEW.product_id
;

Open in new window

0

Featured Post

ClickHouse in a General Analytical Workload

We have mentioned ClickHouse in some recent posts, where it showed excellent results.

In this article on Experts Exchange, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question