Insert into two tables in one command line

Posted on 2005-04-29
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

    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 68

    Assisted Solution

    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


    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

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Join & Write a Comment

    Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
    Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
    Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
    Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

    729 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

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now