December 27, 2019 at 3:36 pm
i have a table where it has 1 million rows. i want to generate deployment script like insert script where it should add GO after each 10,000 records.
is there an option in sql server 2014 while generating scripts?
December 27, 2019 at 4:18 pm
If you're generating individual INSERT/VALUES statements, I wouldn't do that because it will take a month of Sundays to complete 1 million rows. In fact, most methods will not to mention the fact that such a thing will negate all possibility of minimal logging.
We need more information...
--Jeff Moden
Change is inevitable... Change for the better is not.
March 20, 2020 at 11:05 pm
What did you end up doing for this? Inquiring minds want to know. 😀
--Jeff Moden
Change is inevitable... Change for the better is not.
March 21, 2020 at 12:27 am
Couldn't you use TOP with OFFSET to get a fixed size chunk of records and insert that way? (So modify to do the insert in chunks?
use AdventureWorks2017;
GO
DECLARE @NumRows INT = 10;
WHILE @NumRows <= 40
BEGIN
SELECT
[name],
listprice
FROM
production.product
ORDER BY
listprice,
[name]
OFFSET @NumRows ROWS
FETCH NEXT 10 ROWS ONLY;
SET @NumRows = @NumRows + 10;
END
March 21, 2020 at 1:53 am
How about doing something like BCP OUT to write the records to some manageable number of text files, and then use BULK INSERT to insert each file of, say, 100K records?
https://docs.microsoft.com/en-us/sql/tools/bcp-utility?view=sql-server-ver15
March 21, 2020 at 3:25 am
That was going to be my suggestion if the OP ever came back on this thread except I wouldn't limit the batches. First, BCP automatically limits itself to 1,000 rows per batch on the output (and the output should be sorted by an ORDER BY). Then, use BULK INSERT (which is a little bit faster than BCP) to do the import. It's nasty fast just about any way but if you can get minimal logging to happen with TABLOCK and an import order, you can get twice as fast as nasty fast across 2 million rows and not have to chunk up anything.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply