|
|
|
|
![]() ![]() |
Sep 10 2004, 03:46 PM
Post
#1
|
|
|
Member [ Level 2 ] Group: Members Posts: 55 Joined: 7-September 04 Member No.: 351 |
I'm trying to insert about 500 rows into mysql, but I keep getting errors. If I copy and paste too many (about 50) insert statements at a time I get errors sometimes. I sometimes even get errors but then the row is skipped so I don't know there was an error (I'm using linux and SSH).
What's the best way to get my insert statements to put the data in MySQL? Is there anyway that I can have it tell me if there where any errors all the statements are executed? Thanks for your help. |
|
|
|
Jul 15 2008, 05:17 AM
Post
#2
|
|
|
Newbie [ Level 1 ] Group: Members Posts: 0 Joined: 1-November 07 Member No.: 25,869 |
bulk insertion into two tables
MySQL - Trouble With Bulk Insert Statements Hi Can anybody help me previously I am able to work with bulk insertion But I don't know how to use it for insertion into two tables Here is my criteria I am having two tables 1) labdata 2) labdatainfo In labdatainfo there is one auto generated column this column is the forgein keyfor the labdata table when a record is inserted it should first insert in labdatainfo and then it should be inserted in labdata Can anybody help me -question by sumanth |
|
|
|
Jul 18 2008, 02:27 PM
Post
#3
|
|
|
Advanced Member Group: [HOSTED] Posts: 155 Joined: 3-April 08 From: Milling about Member No.: 29,596 |
There is really not enough information to answer you question completely. Most likely you will need more than one INSERT statement. The RDBMS may have a non ANSI SQL method for inserting into multiple tables with one statement though.
Your best bet is to write a procedure for what ever insertion method you are using. |
|
|
|
Jul 20 2008, 12:20 AM
Post
#4
|
|
|
Premium Member Group: [HOSTED] Posts: 377 Joined: 17-June 06 From: Adblock life Member No.: 13,992 |
QUOTE Hi Can anybody help me previously I am able to work with bulk insertion But I don't know how to use it for insertion into two tables Here is my criteria I am having two tables 1) labdata 2) labdatainfo In labdatainfo there is one auto generated column this column is the forgein keyfor the labdata table when a record is inserted it should first insert in labdatainfo and then it should be inserted in labdata Can anybody help me Just write two insertion statements, one that inserts the data into labdatainfo and one into labdata. So say your insertion statement for labdatainfo is something like the following: CODE mysql_query("INSERT INTO labdatainfo (title, data) VALUES ('theTitle', 'theData')"); After you call this, php has a nice function called mysql_insert_id() that will retrieve the primary key of the most recent insert. So you would then call mysql_insert_id, grab the unique id and then insert that id into labdata as the foreign key. I.e: CODE $id = mysql_insert_id(); mysql_query("INSERT INTO labdata (foreignkey) VALUES ('$id')"); The key to your question is probably just that php function. :-) It's quite the obscure function too, for something so useful. As for your question suicide, I'm not sure what you're asking. Are you unable to automate the data that you have to insert instead of writing 500 different insert statements? This post has been edited by Arbitrary: Jul 20 2008, 12:21 AM |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 12th October 2008 - 11:37 AM |