Forum Moderators: open

Message Too Old, No Replies

Many VALUES on one INSERT

Is there a limit?

         

sawatkins

8:53 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Can I insert 350 values on one query?

Here's a sample INSERT:
(NULL , '1-04-2007 00:00:00', '0' , '0' , NULL, NULL)

G

syber

8:57 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Only if the data already exists in another table. In that case you can create an INSERT on top of a SELECT.

INSERT mytable (col1, col2, col3, col4, col5, col6)
SELECT a, b, c, d, e, f
FROM anothertable
WHERE <some condition>

sawatkins

9:09 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Right, then.

In light of that information, let me pose another question.

I need to dynamically insert 390 values into a table. I can easily group information by 12s and 30s.

Given that this operation is only going to happen twice a month, what's your in terms of performance?

Should I run a query to INSERT 30 values 12 times, or 12 values 30 times?

</g>

coopster

11:19 pm on Apr 3, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you asking if you can insert multiple rows in a single statement? Yes, you can if you use the VALUES syntax which can insert multiple rows. To do this, include multiple lists of column values, each enclosed within parentheses and separated by commas.

INSERT INTO mytable (col1, col2, col3, col4, col5, col6) VALUES 
(NULL , '1-04-2007 00:00:00', '0' , '0' , NULL, NULL),
(NULL , '1-04-2007 00:00:00', '0' , '0' , NULL, NULL),
(NULL , '1-04-2007 00:00:00', '0' , '0' , NULL, NULL),
(NULL , '1-04-2007 00:00:00', '0' , '0' , NULL, NULL);

Be careful you aren't writing duplicate keys though.

sawatkins

11:48 pm on Apr 3, 2007 (gmt 0)

10+ Year Member



Yes, I know that much. The question is, I can't insert 350 values at once (I tried).

So I'm wondering if there's a rule or any advice anyone has, since I'm to have to do multiple INSERTS, which is code-inefficient.

So, should I do 30 at once 12 times, or should I do 12 at once 30 times?

</g>

coopster

12:01 am on Apr 4, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've done a lot more than that. Which database are you using? What error message do you receive upon attempting your INSERT?

LifeinAsia

4:02 pm on Apr 4, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



It's probably best to do your own testing on your own server with your own configuration. One person's benchmarks on a completely different system from yous won't mean much.