What you actually want is unclear, however, you could likely get some very good performance by doing this in only a couple of batches. I don't understand why you are getting a value(of Hersteller
) from your table (Artikel
) only to insert it into the table again, but I've incorporated that anyway.
This does the INSERT
in 2 batches of 5,000,000:
WITH N AS(
SELECT N
FROM (VALUES(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL),(NULL))N(N)),
Tally AS(
SELECT ROW_NUMBER() OVER (ORDER BY (SELECT NULL)) AS I
FROM N N1, N N2, N N3, N N4, N N5, N N6, N N7), --10,000,000 rows
Dataset AS(
SELECT TOP (5000000)
A.Hersteller
FROM dbo.Artikel A
CROSS JOIN Tally T)
INSERT INTO dbo.Artikel
SELECT D.Hersteller,
FLOOR(RAND() * (100000000000-101 + 1)) + 101, --This'll be the same for every row, is that intended?
REPLACE(NEWID(),'-',''),
REPLACE(NEWID(),'-',''),
ROUND(RAND(CHECKSUM(NEWID())) * (9999), 2) --This'll be the same for every row, is that intended?
FROM Dataset D;
GO 2
Note my comment about RAND
, and that it'll produce the same value on every row (within the batch). If that isn't desired then see this post about making a random number per row: How do I generate a random number for each row in a T-SQL select?