• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

possible to insert data into two tables from one sql?

 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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..
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1879
MySQL Database Suse
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
reply
    Bookmark Topic Watch Topic
  • New Topic