Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

possible to insert data into two tables from one sql?

 
tormod eriksen
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i would like to insert various data from one table into two different tables in one sql query.
is this possible?
how can it be done?
thanks..
 
capricorn
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
u could use a trigger on insert into the first table to insert a record into the second table.
if the tables are quite different u can create a new table, a trigger on insert for it and in the trigger to insert records into the first two tables
 
Jamie Robertson
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can't do it. You can however use a StoredProcedure to execute multiple inserts/queries together. Although it seems a little overboard for 2 inserts. I would just use 2 separate inserts in a transaction.
Jamie
 
Ali Hassaan
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
NO man if you can do this if you are using Oracle 9i, this is the best feature Oracle 9i provides
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)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic