Mysql
 sql >> Database >  >> RDS >> Mysql

MySQL Trigger per inserire dati in DB diversi

Usa semplicemente la seguente sintassi nella tua istruzione select:

INSERT INTO axis.axis_data
        (projinfo_table_id, rate_user, name,
         property_owner, property_address, property_city,
         property_state, property_zip, property_phone,
         rating_date, rating_type, rating_reason, rating_number,
         field1, field2
        )  

    SELECT NEW.id, user(), NEW.BLGNAME,
         NEW.POWNER, NEW.STREET, NEW.CITY,
         NEW.STATE, NEW.ZIP, NEW.PHONE,
         NEW.RATDATE, NEW.RATTYPE, NEW.RATREAS, NEW.RATNGNO,
         c.field1, c.field2
    FROM COMP c WHERE c.id = NEW.id

Se COMP non ha sempre un record corrispondente in PROJ, puoi usare SELECT ... FROM DUAL LEFT JOIN COMP c ON c.id = NEW.id