User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 402,036 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,450 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.

Nested insert queries in a single query

Join Date: Oct 2005
Location: Manchester, UK
Posts: 481
Reputation: pty is on a distinguished road 
Rep Power: 3
Solved Threads: 31
pty's Avatar
pty pty is offline Offline
Posting Pro in Training

Re: Nested insert queries in a single query

  #2  
Jul 15th, 2007
Originally Posted by SubeeshBabu View Post
hi ,
I have four different tables, all are linked together using foreign key relationships.
Now i need to insert data in to the tables.How can i use nested insert queries to insert data by a single query?


I suggest using transactions (you need the InnoDB storage engine for this).

  1. start transaction
  2. INSERT INTO blah...
  3. INSERT INTO blah...
  4. commit

If one of your statements causes an error none will be committed so you won't get corrupted data / missing keys etc.
Note to self... pocket cup
Reply With Quote  
All times are GMT -4. The time now is 10:57 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC