Solved

Update Trigger help

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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

SQL Command Tool comes with APEX under SQL Workshop. It helps us to make changes on the database directly using a graphical user interface. This helps us writing any SQL/ PLSQL queries and execute it on the database and we can create any database ob…
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
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…

776 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