How to Insert 1000 Rows At a Time

How to insert 1000 rows at a time

I create a student table with three column id, student,age. show you this example

declare @id int 
select @id = 1
while @id >=1 and @id <= 1000
begin
insert into student values(@id, 'jack' + convert(varchar(5), @id), 12)
select @id = @id + 1
end

this is the result about the example
enter image description here

INSERT more than 1000 rows into SQL Server database from JSON in C# code

You should insert each row one by one.

https://www.red-gate.com/simple-talk/sql/performance/comparing-multiple-rows-insert-vs-single-row-insert-with-three-data-load-methods/

Gist - 23 columns means inserting more than 2 at a time isn't worth it. Time wise, single row inserts is almost as fast as multiple row inserts. There is a case where stringifying your parameters can give you a 50% boost, but IMO not worth it. If you reduce your columns to 2 or even 7 it might be worth it.

Take those estimates with a grain of salt - the performance of the box may affect the relative benefits.

Of course keeping your row inserts to one at a time makes it easy to parameterize your query and keep things clear while eliminating the potential of sql injection. Not having to compile the sql everytime, while doing most of the parameter work on the client can help a lot also.

Oracle insert 1000 rows at a time

It is rather doubtful that this will really improve performance particularly given the simplicity of the SELECT statement. That must be doing either a full scan of the table or of an index on author. If that scan is slow, you're much better off diagnosing the underlying problem rather than trying to work around it (for example, perhaps oldDB.MsgLog has a number of empty blocks below the high water mark that forces a full table scan to read many more blocks than is strictly necessary).

If you really want to write some more verbose and less efficient PL/SQL to accomplish the task, though, you certainly can

DECLARE
TYPE tbl_authors IS TABLE OF msg.author%TYPE;
l_authors tbl_authors;

CURSOR author_cursor
IS SELECT author
FROM oldDB.MsgLog;
BEGIN
OPEN author_cursor;
LOOP
FETCH author_cursor
BULK COLLECT INTO l_authors
LIMIT 1000;

EXIT WHEN l_authors.count = 0;

FORALL i IN 1..l_authors.count
INSERT INTO msg( author )
VALUES( l_authors(i) );
END LOOP;
END;

Insert 1000 rows in php each time different

The original loop is nearly correct, with the exception of the 2nd statement. It should be a comparison, instead you are setting.

Correct version for($i=1;$i<=1000;$i++){. Notice the $i <= 1000; instead of $i = 1000;.

Android SQ Lite - How to insert more than 1000 rows at a time efficiently?