Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> MySQL - Trouble With Bulk Insert Statements
suicide
post Sep 10 2004, 03:46 PM
Post #1


Member [ Level 2 ]
Group Icon

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.
Go to the top of the page
 
+Quote Post
iGuest
post Jul 15 2008, 05:17 AM
Post #2


Newbie [ Level 1 ]
Group Icon

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
Go to the top of the page
 
+Quote Post
Darasen
post Jul 18 2008, 02:27 PM
Post #3


Advanced Member
Group Icon

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.

Go to the top of the page
 
+Quote Post
Arbitrary
post Jul 20 2008, 12:20 AM
Post #4


Premium Member
Group Icon

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
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. MySQL Realtime Replication(4)
  2. Recover Tables From A MySQL .frm File(8)
  3. Mirror My MySQL Database To Another Mysql Server(4)
  4. How To Connect MySQL With Flash?(8)
  5. MySQL Output Database Question(18)
  6. MySQL, Multiple Tables(24)
  7. Navcat For MySQL(9)
  8. Permission Problem With Mysql Database Creation(8)
  9. Mysql And Php(15)
  10. Problems With Php Saving Data Into Mysql(6)
  11. Login System Using A Mysql Db(5)
  12. Oracle Vs. Mysql Vs. Postgresql(9)
  13. Subqueries In Mysql(1)
  14. Apache Php With Mysql On Windows [solved](9)
  15. Not Understanding Mysql(4)
  1. Mysql Script Help(3)
  2. Mysql - So Hard(14)
  3. Mysql Problem(1)
  4. Sun Bought Mysql(6)
  5. Mysql Backup With Another Address?(4)
  6. I Have An Error With My Mysql Connection(7)
  7. Mysql And User File_priv(0)
  8. Mysql Database Management(1)
  9. Mysql Database Entry By Excel Sheets(2)
  10. Mysql On Computer(9)
  11. Any Website Provide Free Host Mysql Host?(4)
  12. Mysql Multiple Tables(1)
  13. Mysql Overhead(3)


 



- Lo-Fi Version Time is now: 12th October 2008 - 11:37 AM