DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 11 of 11
  1. #1
    Join Date
    Oct 2005
    Posts
    95

    SQL Insert data in Multiple table and Update at same time

    Hi

    I have a question about How to insert and update data using Multiple tables . I need to insert data into two SQL table from one query ( insert statement ) and able to update that tables with a one update command . How do I do that . I think I have to use Inner jnoin but it is not working . Can any one give me the syntax of the SQL statement . I am using SQL server 2000 .

    Thanks

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    I believe you may only INSERT into or UPDATE one table per SQL statement. You may, however, include multiple statements in a single query; separate the statement with a semi-colon.
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  3. #3
    Join Date
    Oct 2005
    Posts
    95

    Insert and update multiple tables at at time

    Hi

    Thanks for your reply . It worked . I can insert and update multiple SQL Server table at same time now

    Thanks

  4. #4
    Join Date
    Dec 2005
    Posts
    1
    Hi,

    I am trying to do something similar, but have not been able to figure out how to insert data on two different tables from one submission form.

    For example, I have a form that asks for the following data (from users registering):

    Username
    Password
    Email Address

    I would like to insert username and password in one table (table1) and the email address in a different table (table2).

    I am using PHP/MySQL for this.

    How would I insert data from one form into two tables?

    Thanks for you help,

    Ray

  5. #5
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    8,387
    Phil Weber
    http://www.philweber.com

    Please post questions to the forums, where others may benefit.
    I do not offer free assistance by e-mail. Thank you!

  6. #6
    Join Date
    Dec 2005
    Posts
    1
    I'm really struggling with inserting data to more than one table from a single form as well. Starting to think it might make more sense to load all the form data to a single table and query just the single. If inserting INTO more than one table is this much hassle, I can only imagine how successfully querying OUT OF more than one will be. ;-) Has anyone seen any good tutorials with examples for PHP and MySQL on the net?

  7. #7
    Join Date
    Jan 2008
    Posts
    1
    How to insert records into both the tables in a "single query" in SQL SERVER 2005

  8. #8
    Join Date
    Apr 2007
    Location
    Sterling Heights, Michigan
    Posts
    8,649
    Welcome to DevX
    Quote Originally Posted by ramakrishnan
    How to insert records into both the tables in a "single query" in SQL SERVER 2005
    I believe this still applies.
    Quote Originally Posted by Phil Weber
    I believe you may only INSERT into or UPDATE one table per SQL statement. You may, however, include multiple statements in a single query; separate the statement with a semi-colon.
    Any particular reason why you don't want to use more than one SQL statement?
    I don't answer coding questions via PM or Email. Please post a thread in the appropriate forum section.
    Please use [Code]your code goes in here[/Code] tags when posting code.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    Modifications Required For VB6 Apps To Work On Vista

  9. #9
    Join Date
    Dec 2011
    Posts
    1
    Phil's feedback would be a tad clearer if it said you can string one SQL statement after another, seperated by semi-colons (for those who do not yet really understand that multiple SQL Statements can make up a query).
    However, this is not the same as creating one SQL Statement to insert into multiple tables.

  10. #10
    Join Date
    Feb 2012
    Posts
    1
    Quote Originally Posted by Phil Weber View Post
    I believe you may only INSERT into or UPDATE one table per SQL statement. You may, however, include multiple statements in a single query; separate the statement with a semi-colon.
    Thank you so much Phil!
    I've never really had experience with SQL databases before and I've been looking for a way to UPDATE multiple tables in one SQL statement without success...

    Rather stupid as it sounds, I hadn't thought about just seperating the statement into multiple statements with a semi-colon!
    Unfortunately, I seem to have drawn the short-straw on integrating a clients SQL database with our system while our database engineer is AWOL, so this post has pretty much just saved my life!

    ~ Ray

  11. #11
    Join Date
    Feb 2012
    Posts
    1
    Quote Originally Posted by Phil Weber View Post
    I believe you may only INSERT into or UPDATE one table per SQL statement. You may, however, include multiple statements in a single query; separate the statement with a semi-colon.
    Alternately you can place a go inbetween statements. If all transactions must complete before committing you can surround your statements with a begin tran and commit tran or rollback tran if something went wrong.

Similar Threads

  1. query tuning
    By dhaya in forum Database
    Replies: 11
    Last Post: 08-25-2003, 05:24 PM
  2. Replies: 1
    Last Post: 08-19-2003, 12:12 PM
  3. Replies: 1
    Last Post: 07-17-2003, 11:36 AM
  4. Loading Data To SQL Table
    By Bill in forum VB Classic
    Replies: 5
    Last Post: 10-03-2000, 03:52 PM
  5. UPDATE DATA GRID VALUES TO THE TABLE
    By VAMM in forum VB Classic
    Replies: 2
    Last Post: 05-09-2000, 06:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links