Results 1 to 3 of 3

Thread: Insert Query

  1. #1
    Join Date
    Jan 2004
    Posts
    67

    Unanswered: Insert Query

    hi,

    Is there a way to Insert into multiple tables using a single query

    thanks
    Shankar

  2. #2
    Join Date
    Aug 2003
    Location
    Where the Surf Meets the Turf @Del Mar, CA
    Posts
    7,776
    Provided Answers: 1
    Possibly, but even asking this question make wonder & scratch my head about any design/architecture which would make inserting into more than one table "from a single query".
    Is the application in Third Normal Form?

  3. #3
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Definitely (in 9i). An example from the SQL Reference manual http://download-west.oracle.com/docs...a.htm#2125349:

    INSERT ALL
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date, sales_sun)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+1, sales_mon)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+2, sales_tue)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+3, sales_wed)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+4, sales_thu)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+5, sales_fri)
    INTO sales (prod_id, cust_id, time_id, amount)
    VALUES (product_id, customer_id, weekly_start_date+6, sales_sat)
    SELECT product_id, customer_id, weekly_start_date, sales_sun,
    sales_mon, sales_tue, sales_wed, sales_thu, sales_fri, sales_sat
    FROM sales_input_table;

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •