Solved

Problem with trigger

Posted on 2011-02-17
1
828 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How can i Install a new Data Source on Visual Studio 2 94
Mysql Crashing Intermittently 16 82
Duplicating MySQL Table columns 5 32
Easy to use inventory management software 7 69
Foreword In the years since this article was written, numerous hacking attacks have targeted password-protected web sites.  The storage of client passwords has become a subject of much discussion, some of it useful and some of it misguided.  Of cou…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

896 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now