DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/)
-   MySQL (http://www.daniweb.com/forums/forum126.html)
-   -   Nested insert queries in a single query (http://www.daniweb.com/forums/thread83434.html)

SubeeshBabu Jul 13th, 2007 7:32 am
Nested insert queries in a single query
 
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?

pty Jul 15th, 2007 10:32 am
Re: Nested insert queries in a single query
 
Quote:

Originally Posted by SubeeshBabu (Post 403072)
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).

start transaction
  insert into blah...
  insert into blah...
commit

If one of your statements causes an error none will be committed so you won't get corrupted data / missing keys etc.


All times are GMT -4. The time now is 10:55 am.

Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC