Posted by: R Manimaran | July 4, 2008

Inserting Random Values into SQL SERVER Table

Inserting Random numbers into a Table Column

We may have a situation to insert some random numbers into our table. For that purpose we can use the Rand() Function which is available in SQL SERVER.


Set noCount on

— Declare a Table

Declare @Table1 Table(id int,Rndvalue int)

Declare @index int

select @index=1

— insert 10 Random values into the Table

while @index<11


–Generate Random Values

Insert into @Table1 values(@index,ceiling(1000*Rand()))

–Increment the id value

Select @index=@index+1


—-Select the values

Select id,RndValue from @Table1


Random Values insertion

Random Values insertion



  1. awesome.

Leave a Reply

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

You are commenting using your 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 )

Google+ photo

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

Connecting to %s


%d bloggers like this: