Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

5 Main Tables: TEMP, PAYMENT, CUSTOMER, PURCHASE, and PRODUCT.

  • TEMP: TempID, Email, Name, Product1, Product2, Date, Amount
  • PAYMENT: PaymentID, Status, Amount, Date
  • CUSTOMER: CustomerID, Email, Name
  • PURCHASE: CustomerID, PaymentID, ProductID, Quantity
  • PRODUCT: ProductID, ProductName, Price

How to insert each field from TEMP where TEMP.Email = '$Email' to PAYMENT, CUSTOMER, PURCHASE, and PRODUCT:

  • TEMP.Email >> CUSTOMER.Email
  • TEMP.Name >> CUSTOMER.Name
  • TEMP.Product1 >> PURCHASE.ProductID
  • TEMP.Product2 >> PURCHASE.ProductID
  • TEMP.Date >> PAYMENT.Date
  • TEMP.Amount >> PAYMENT.Amount
share|improve this question

1 Answer 1

You could write an (AFTER?) INSERT trigger, like this:

CREATE TRIGGER temp_inserts_trg AFTER INSERT ON temp
    FOR EACH ROW BEGIN
        INSERT INTO customer VALUES(NEW.ID, NEW.Email, NEW.Name);
        INSERT INTO payment...
        ...
    END;

Check the MySQL CREATE TRIGGER documentation for more info.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.