wood burning stoves 2.0*
The moose likes JDBC and the fly likes possible to insert data into two tables from one sql? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Bookmark "possible to insert data into two tables from one sql?" Watch "possible to insert data into two tables from one sql?" New topic
Author

possible to insert data into two tables from one sql?

tormod eriksen
Ranch Hand

Joined: Jan 23, 2002
Posts: 52
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

Joined: May 30, 2002
Posts: 2
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

Joined: Jul 09, 2001
Posts: 1879

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

Joined: May 16, 2001
Posts: 103
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)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: possible to insert data into two tables from one sql?
 
Similar Threads
create tables using java code by fetching from .sql file
Question on database access
Copy data from one table to another
SQL queries
Multiple Tables