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

Update Trigger help

Posted on 2013-05-20
4
352 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 109

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 109

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article explains all about SQL Server Piecemeal Restore with examples in step by step manner.
CCModeler offers a way to enter basic information like entities, attributes and relationships and export them as yEd or erviz diagram. It also can import existing Access or SQL Server tables with relationships.
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…

791 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