?
Solved

Update Trigger help

Posted on 2013-05-20
4
Medium Priority
?
361 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
[X]
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
  • 2
  • 2
4 Comments
 
LVL 111

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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Recently, Microsoft released a best-practice guide for securing Active Directory. It's a whopping 300+ pages long. Those of us tasked with securing our company’s databases and systems would, ideally, have time to devote to learning the ins and outs…
In this article, we’ll look at how to deploy ProxySQL.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

752 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