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
Solved

Problem with trigger

Posted on 2011-02-17
1
830 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
1 Comment
 
LVL 59

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

840 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