On 2/28/07, Christian POMPIER <[EMAIL PROTECTED]> wrote:
Could i make to insert 10 000 row in my table with a loop ?



Christian,

This kind of a question is likely to either not result in an answer,
or in an answer that is unsatisfactory to you -- either way, bandwidth
wasted. Ask better questions, get better answers. Specify whether you
are looking for SQL help, or help with a specific programming
language. Either way, specify what you have tried already, unless it
is something that is so difficult to try first that it merits asking
first.

Why even bother asking for "10,000" rows... if you know how to insert
more than 1 row, you can insert a million rows. You might want to ask
about efficiency of process, optimization, etc.

We have to guess from your question -- your real question is on using
a loop, but you don't specify any language. Are you programming in C,
or a scripting language, or Java?

Below is Perl-ish psuedo code (because Perl is what I know), which you
can adapt to your language --

# set db autocommit to false, so inserts are really fast
my dbh = (blah blah { autocommit => false } );

# prepare the statement in advance, so it doesn't
# have to be prepared for each row. Use bind variables
my statement = dbh("INSERT INTO tbl (a, b) VALUES (?, ?)");

# get an array of your 10,000 values. Here, it is an array of arrays
my array_of_arrays = (row1 .. row10000);

# loop over the array and insert
foreach my row (array_of_arrays) {
 statement->execute(row[0], row[1]);
}

# commit to the db
dbh->commit;

Writing all of the above should take you 5 mins. Inserting it should
take a fraction of a second.

Hope this helps.

--
Puneet Kishor http://punkish.eidesis.org/
Nelson Inst. for Env. Studies, UW-Madison http://www.nelson.wisc.edu/
Open Source Geospatial Foundation http://www.osgeo.org/education/
---------------------------------------------------------------------
collaborate, communicate, compete
=====================================================================

-----------------------------------------------------------------------------
To unsubscribe, send email to [EMAIL PROTECTED]
-----------------------------------------------------------------------------

Reply via email to