I try to insert some dummy data inside my table using a WHILE, but it run really really slow.
I was thinking maybe I am writing not properly the code, could yo please have a look and confirm it?
-- Insert dummy data
DECLARE
@i int,
@Content int;
SET @i = 5001;
WHILE @i > 5000 AND @i < 10000
BEGIN
SET @Content = ROUND(((10000-5000)*RAND()+5000),0)
INSERT INTO dbo.CmsImagesContents
(ContentId, Title, AltTag, Caption)
VALUES
(@Content,'Test Title', 'Test AltTag', 'Test Caption');
SET @i = @i + 1;
END
Rather than doing 4999 separate insert statements in a loop, you’ll get much better performance if you do a single insert of all 4999 rows. So, if you have a table #T containing 4999 rows you would simply call the following:
If you need to create such a table of 4999 rows in the first place then the following SQL would work for you: