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. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

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.