Solved

Update Trigger help

Posted on 2013-05-20
4
343 Views
Last Modified: 2013-06-26
Hi Experts,

I need help with an UPDATE TRIGGER for MySql.

I have two mysql databases.
I want to update 2 columns in database 2 by a user_id when a date column in database 1 is updated.
I only want to do the updates if they are a specific product id.

Is what I have done below the best way to write an update trigger.
I get an "unknow table 'Database1.xxx_users_products_jn.' in fieldlist" error
Does this logic work?

Here is what I have done.
Please advise on how to make this work

Thanks

Matt


BEGIN
 If Database1.xxx_users_products_jn.product_id in (1,2,3,4,11,12,13,14,15,26,27,42,53) then
       UPDATE Database2.usrprofiles
        SET
              Database2.usrprofiles.Active = 1,
            Database2.usrprofiles.DisableDate = NEW.Database1.access_end_date
        WHERE
              Database2.usrprofiles.user_id = Database1.xxx_users_products_jn.user_id
            AND Database1.xxx_users_products_jn.access_end_date >= NOW()
            ;
 END if;
END
0
Comment
Question by:matthewdacruz
  • 2
  • 2
4 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
ID: 39181186
It looks like you've obscured the database and table names for this question.  Can you use phpMyAdmin or a similar tool to verify that Database1.xxx_users_products_jn actually exists?  The name is probably case-sensitive.
0
 

Author Comment

by:matthewdacruz
ID: 39181254
Figured out what i had to do. I removed all the database1.table_names and it worked.

Is this the best way of writing the trigger though. The logic
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39181304
Then I'm guessing you have selected database1, so that is the assumed data base when looking for a table.

While I think a TRIGGER is certainly appropriate for this, you could probably also do the same thing with a couple of if() statements in program code.  You might also want to wrap this in a TRANSACTION.  These SitePoint articles appear to be pretty spot-on.
http://www.sitepoint.com/database-triggers-events/
http://www.sitepoint.com/how-to-create-mysql-triggers/
0
 

Author Closing Comment

by:matthewdacruz
ID: 39277968
Thanks Ray, That helped
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

This article describes some very basic things about SQL Server filegroups.
Shadow IT is coming out of the shadows as more businesses are choosing cloud-based applications. It is now a multi-cloud world for most organizations. Simultaneously, most businesses have yet to consolidate with one cloud provider or define an offic…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

758 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

18 Experts available now in Live!

Get 1:1 Help Now