Insert into two tables in one command line

Posted on 2005-04-29
Medium Priority
Last Modified: 2010-03-19
INSERT INTO some_table (column1, column2) VALUES (" &pblah& "," &pblah2& ")"

How do I change the above to insert into two tables at once? I tried: INSERT INTO some_table, some other table (and the rest was the same), but that didn't work.?
Question by:net_susan
LVL 28

Accepted Solution

rafrancisco earned 1600 total points
ID: 13895262
You cannot insert into 2 tables using just one INSERT statement.  You have to issue 2 separate INSERT statements:

INSERT INTO some_table1 (column1, column2) VALUES (" &pblah& "," &pblah2& ")"
INSERT INTO some_table2 (column1, column2) VALUES (" &pblah& "," &pblah2& ")"
LVL 70

Assisted Solution

by:Scott Pletcher
Scott Pletcher earned 200 total points
ID: 13895278
True.  Even if you create a view -- which could reference both tables, of course -- and try to insert into it, you can only insert to one table in the view at a time.
LVL 13

Assisted Solution

ispaleny earned 200 total points
ID: 13895308

INSERT INTO some_tableA (column1, column2) VALUES ("  &pblah& "," &pblah2& ")"
INSERT INTO some_tableB  (column1, column2) VALUES (" &pblah& "," &pblah2& ")"

then you are sure it is atomical (done at once)

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how the fundamental information of how to create a table.
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question