Home > database >  Setting up a trigger to update one table from another table inside mySQL
Setting up a trigger to update one table from another table inside mySQL

Time:03-06

Ultimately what I'm trying to do is this:

When CCT1 is updated, also update CCT2.

What Row? The row with the matching ID (CCT1 ID:16 = CCT2 ID:16)

CCT1: ’O1cUxE_jet_cct_raffles.raffle_id’

CCT2: ’O1cUxE_rafflepro_tickets_setting.category_id’

From data entered into a specific column in CCT1: ‘O1cUxE_jet_cct_raffles.raffle_start_date’

I’d like to update a specific column in CCT2: ‘O1cUxE_rafflepro_tickets_setting.raffle_dates_from’

Here's what I've got so far... I'm sure its not even close haha.

Screenshot


CREATE TRIGGER `Update Raffle Ticket Pro` AFTER UPDATE ON `O1cUxE_jet_cct_raffles`
FOR EACH ROW UPDATE O1cUxE_rafflepro_tickets_setting
SET raffle_dates_from = O1cUxE_jet_cct_raffles.raffle_start_date
WHERE O1cUxE_rafflepro_tickets_setting.category_id = O1cUxE_jet_cct_raffles.raffle_name

CodePudding user response:

the old values befpre the UPDATe you get by using for example OLD.raffle_start_date

The updated Values you get by using for example NEW.raffle_start_date

CREATE 
    TRIGGER  `Update Raffle Ticket Pro`
 AFTER UPDATE ON `O1cUxE_jet_cct_raffles` FOR EACH ROW 
    UPDATE O1cUxE_rafflepro_tickets_setting 
      SET raffle_dates_from = NEW.raffle_start_date 
      WHERE O1cUxE_rafflepro_tickets_setting.category_id = NEW.raffle_name
  • Related