INSERT 100,000 RANDOM ROWS IN SQL SERVER

Many times, we will require sample datasets with any random values but in large quantities, perhaps hundreds of thousands. Alternatively, during data analysis, we may need to insert a large number of rows. The example below shows a loop statement that inserts 100,000 rows into a table to help achieve both of the above aims.

CREATE TABLE tbStudent(bigID BIGINT, StudentName VARCHAR(50))
GO

DECLARE @bigid BIGINT
SELECT @bigid = 2200000000  — it can be 0 or 1.
WHILE @bigid >=2200000000 and @bigid <= 2200100000
BEGIN
INSERT INTO tbStudent VALUES(@bigid, ‘Student_’ + CONVERT(VARCHAR(15), @bigid))
SELECT @bigid = @bigid + 1
END
GO

Now, let’s use COUNT_BIG function to see the values.
SELECT COUNT_BIG(bigID) FROM tbStudent

I hope you found this post to be informative.

To receive notifications of new posts, please subscribe.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s