pf » Multiple Inserts with MySQL

Multiple Inserts with MySQL

databases

Andy Jarrett posted this technique for insterting multiple rows (bulk insert) in one SQL statement a few months ago. It's a handy trick:

INSERT INTO x (a,b)
VALUES 
 ('1', 'one'),
 ('2', 'two'),
 ('3', 'three')

I tried that on a couple hundred thousand rows today, and I got an error that my statement was bigger than the Max Allowed Packet size in MySQL. So keep that in mind when using. You can either change the setting, or go about it a different way.


Need Help With SQL?
SQL & Database Training Classes - Instructor Led Online Training Classes for SQL, MySQL, Oracle, and SQL Server.

Related Entries
11 people found this page useful, what do you think?

WAF for CF
Trackback Address: 379/0D1EEEAD85EC4EA978503A0A6E9D6632
On 06/10/2005 at 5:57:42 PM MDT Mr K wrote:
1
This is all good and well if you are inserting the exact same information into multiple tables, but what if you want to insert into 2 or more tables the information from ONE form, but each table has different sets of information. You have to then do it as 2 or more seperate INSERTS :(

On 04/11/2006 at 12:08:39 AM MDT sarah wrote:
2
hi, how do you insert data from one record's column into another record's column in the same table. p.s the columns from where and to where data is being transfered is the same column in the same table.

On 07/24/2007 at 10:53:09 PM MDT nurez wrote:
3
re: how do you insert data from one record's ..?

using inner join... its helps vour u

On 08/31/2007 at 5:16:53 AM MDT Rajesh wrote:
4
God bless Andy!By far, this has been the best tip that someone ever gave in a forum. It greatly reduced my burden of inserting 10 Mil rows..

On 09/26/2007 at 5:09:12 PM MDT kendall wrote:
5
you could use transactions to insert in to multiple tables.

On 10/05/2007 at 4:55:40 PM MDT Derrick wrote:
6
OK, so how can I do this with CFQUERY? When working with MySQL (PhpMyAdmin), this works fine--> [ INSERT into table (colA, colB, colC, colD) VALUES (1958, 106165412, 'stuff', 1), (1958, 106165412, 'stuff', 1), (1958, 106165412, 'stuff', 1), (1958, 106165412, 'stuff', 1), (1958, 106165412, 'stuff', 1) ] But if I wrap it in CFQUERY, ColdFusion (BlueDragon) gives an error. Why?

On 11/30/2007 at 1:43:51 PM MST Dan wrote:
7
You would have to anyway.

RE:

On 06/10/2005 at 5:57:42 PM MDT Mr K wrote: 1 This is all good and well if you are inserting the exact same information into multiple tables, but what if you want to insert into 2 or more tables the information from ONE form, but each table has different sets of information. You have to then do it as 2 or more seperate INSERTS :(

On 02/23/2008 at 7:35:57 AM MST kuchnie wrote:
8
http://www.petefreitag.com/item/379.cfm zajbiste wogole nie ma co elooo

On 02/23/2008 at 7:40:15 AM MST mezszczyzna wrote:
9
My problem is similar to above, please look here http://bling-bling.pl in comments section where im adding comment throght ajax to multiple tables

On 04/03/2009 at 12:03:00 AM MST purnima wrote:
10
I want to insert data from one table to other table. Both the table columns are different. Help me out.




  



Spell Checker by Foundeo





Subscribe to my RSS Feed: solosub RSS
Tags