954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

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?

SubeeshBabu
Newbie Poster
4 posts since Jul 2007
Reputation Points: 10
Solved Threads: 0
 
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.

pty
Posting Pro
530 posts since Oct 2005
Reputation Points: 64
Solved Threads: 39
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You